Search in sources :

Example 1 with IntRingBuffer

use of com.swiftmq.tools.collection.IntRingBuffer in project swiftmq-ce by iitsoftware.

the class StableStore method init.

private void init() throws Exception {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace("sys$store", toString() + "/init ...");
    nFree = 0;
    if (freePoolEnabled)
        freePool = new IntRingBuffer[10];
    filename = path + File.separatorChar + FILENAME;
    emptyData = new byte[Page.PAGE_SIZE];
    // emtpy
    emptyData[0] = 1;
    for (int i = 1; i < Page.PAGE_SIZE; i++) emptyData[i] = 0;
    file = new RandomAccessFile(filename, "rw");
    fileLength = file.length();
    if (fileLength > 0) {
        numberPages = (int) (fileLength / Page.PAGE_SIZE);
        if (!offline)
            shrinkFile();
    } else
        initialize(initialPages);
    sync();
    if (freePoolEnabled)
        buildFreePageList();
    if (!offline) {
        Entity entity = ctx.filesList.createEntity();
        entity.setName(FILENAME);
        entity.createCommands();
        ctx.filesList.addEntity(entity);
        freeProp = entity.getProperty("free-pages");
        usedProp = entity.getProperty("used-pages");
        fileSizeProp = entity.getProperty("file-size");
        sizeCollectProp = ctx.dbEntity.getProperty("size-collect-interval");
        collectInterval = (long) (Long) sizeCollectProp.getValue();
        startTimer();
        PropertyChangeListener propChangeListener = new PropertyChangeListener() {

            public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
                stopTimer();
                collectInterval = (Long) newValue;
                startTimer();
            }
        };
        sizeCollectProp.setPropertyChangeListener(propChangeListener);
        swiftletManagerAdapter = new SwiftletManagerAdapter() {

            public void swiftletStarted(SwiftletManagerEvent event) {
                mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
                mgmtSwiftlet.addMgmtListener(StableStore.this);
            }
        };
        SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", swiftletManagerAdapter);
    }
    ctx.logSwiftlet.logInformation("sys$store", toString() + "/init done, size=" + numberPages + ", freePages=" + getNumberFreePages());
}
Also used : IntRingBuffer(com.swiftmq.tools.collection.IntRingBuffer) Entity(com.swiftmq.mgmt.Entity) SwiftletManagerEvent(com.swiftmq.swiftlet.event.SwiftletManagerEvent) RandomAccessFile(java.io.RandomAccessFile) PropertyChangeListener(com.swiftmq.mgmt.PropertyChangeListener) MgmtSwiftlet(com.swiftmq.swiftlet.mgmt.MgmtSwiftlet) Property(com.swiftmq.mgmt.Property) SwiftletManagerAdapter(com.swiftmq.swiftlet.event.SwiftletManagerAdapter)

Aggregations

Entity (com.swiftmq.mgmt.Entity)1 Property (com.swiftmq.mgmt.Property)1 PropertyChangeListener (com.swiftmq.mgmt.PropertyChangeListener)1 SwiftletManagerAdapter (com.swiftmq.swiftlet.event.SwiftletManagerAdapter)1 SwiftletManagerEvent (com.swiftmq.swiftlet.event.SwiftletManagerEvent)1 MgmtSwiftlet (com.swiftmq.swiftlet.mgmt.MgmtSwiftlet)1 IntRingBuffer (com.swiftmq.tools.collection.IntRingBuffer)1 RandomAccessFile (java.io.RandomAccessFile)1