~ubuntu-branches/ubuntu/maverick/electric/maverick

« back to all changes in this revision

Viewing changes to com/sun/electric/database/geometry/btree/OverflowPageStorage.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-01-09 16:26:04 UTC
  • mfrom: (1.1.4 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100109162604-1ypvmy8ijmlc6oq7
Tags: 8.10-1
* New upstream version.
* debian/control
  - Add libjava3d-java and quilt build dependencies.
  - Update standards version to 3.8.3.
  - Add libjava3d-java as recommends to binary package.
* debian/rules
  - Use quilt patch system instead of simple patchsys.
  - Add java3d related jar files to DEB_JARS.
* debian/patches/*
  - Update as per current upstream source. Convert to quilt.
* debian/ant.properties
  - Do not disable 3D plugin anymore.
  - Use new property to disable compilation of OS X related classes.
* debian/wrappers/electric
  - Add java3d related jar files to runtime classpath.
* debian/README.source
  - Change text to the appropriate one for quilt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- tab-width: 4 -*-
 
2
 *
 
3
 * Electric(tm) VLSI Design System
 
4
 *
 
5
 * File: OverflowPageStorage.java
 
6
 *
 
7
 * Copyright (c) 2009 Sun Microsystems and Static Free Software
 
8
 *
 
9
 * Electric(tm) is free software; you can redistribute it and/or modify
 
10
 * it under the terms of the GNU Lesser General Public License as published by
 
11
 * the Free Software Foundation; either version 3 of the License, or
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * Electric(tm) is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU Lesser General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public License
 
20
 * along with Electric(tm); see the file COPYING.  If not, write to
 
21
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 
22
 * Boston, Mass 02111-1307, USA.
 
23
 */
 
24
package com.sun.electric.database.geometry.btree;
 
25
 
 
26
/**
 
27
 *  Combines two PageStorage objects, using the first until the "high
 
28
 *  water mark" is exceeded, then moving to the other.  Generally the
 
29
 *  first PageStorage is "small but fast" and the second is "large but
 
30
 *  slow".
 
31
 *
 
32
 *  Might not be thread-safe.
 
33
 */
 
34
public class OverflowPageStorage extends PageStorage {
 
35
 
 
36
    private final PageStorage ps1;
 
37
    private final PageStorage ps2;
 
38
    private final int highWaterMark;
 
39
    private boolean overflowed = false;
 
40
 
 
41
    /** Note that highWaterMark is in BYTES, not pages */
 
42
    public OverflowPageStorage(PageStorage ps1, PageStorage ps2, long highWaterMark) {
 
43
        super(Math.max(ps1.getPageSize(), ps1.getPageSize()));
 
44
        this.ps1 = ps1;
 
45
        this.ps2 = ps2;
 
46
        this.highWaterMark = (int)(highWaterMark / getPageSize());
 
47
    } 
 
48
 
 
49
    public int getNumPages() { return overflowed ? ps2.getNumPages() : ps1.getNumPages(); }
 
50
    public synchronized int createPage() {
 
51
        if (overflowed) return ps2.createPage();
 
52
        if (ps1.getNumPages() < highWaterMark) return ps1.createPage();
 
53
        byte[] buf = new byte[getPageSize()];
 
54
        for(int i=0; i<ps1.getNumPages(); i++) {
 
55
            while(ps2.getNumPages() < i+1) ps2.createPage();
 
56
            ps1.readPage(i, buf, 0);
 
57
            ps2.writePage(i, buf, 0);
 
58
        }
 
59
        overflowed = true;
 
60
        ps1.close();
 
61
        return ps2.createPage();
 
62
    }
 
63
    public void fsync(int pageid) { if (overflowed) ps2.fsync(pageid); else ps1.fsync(pageid); }
 
64
    public void fsync() { if (overflowed) ps2.fsync(); else ps1.fsync(); }
 
65
    public void writePage(int pageid, byte[] buf, int ofs) {
 
66
        if (overflowed) ps2.writePage(pageid, buf, ofs);
 
67
        else            ps1.writePage(pageid, buf, ofs);
 
68
    }
 
69
    public void readPage(int pageid, byte[] buf, int ofs) {
 
70
        if (overflowed) ps2.readPage(pageid, buf, ofs);
 
71
        else            ps1.readPage(pageid, buf, ofs);
 
72
    }
 
73
 
 
74
    public synchronized void close() { if (overflowed) ps2.close(); else ps1.close(); }
 
75
}
 
 
b'\\ No newline at end of file'