use of com.swiftmq.swiftlet.event.SwiftletManagerAdapter in project swiftmq-ce by iitsoftware.
the class StoreSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
try {
ctx = new StoreContext(this, config);
ctx.swapFileFactory = createSwapFileFactory();
ctx.swapPath = SwiftUtilities.addWorkingDir((String) ctx.swapEntity.getProperty("path").getValue());
swapMaxLength = ((Long) ctx.swapEntity.getProperty("roll-over-size").getValue()).longValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", "startup...");
ctx.durableStore = createDurableSubscriberStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.durableEntity.getProperty("path").getValue()));
deleteSwaps();
ctx.recoveryManager = new RecoveryManager(ctx);
ctx.stableStore = createStableStore(ctx, SwiftUtilities.addWorkingDir((String) ctx.dbEntity.getProperty("path").getValue()), ((Integer) ctx.dbEntity.getProperty("initial-page-size").getValue()).intValue());
Property minCacheSizeProp = ctx.cacheEntity.getProperty("min-size");
Property maxCacheSizeProp = ctx.cacheEntity.getProperty("max-size");
int minCacheSize = ((Integer) minCacheSizeProp.getValue()).intValue();
int maxCacheSize = ((Integer) maxCacheSizeProp.getValue()).intValue();
if (minCacheSize > maxCacheSize)
throw new Exception("Cache/min-size is invalid, must be less than max-size!");
minCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
int n = ((Integer) newValue).intValue();
if (n > ((Integer) ctx.cacheEntity.getProperty("max-size").getValue()).intValue())
throw new PropertyChangeException("min-size is invalid, must be less than max-size!");
}
});
maxCacheSizeProp.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
int n = ((Integer) newValue).intValue();
if (n < ((Integer) ctx.cacheEntity.getProperty("min-size").getValue()).intValue())
throw new PropertyChangeException("max-size is invalid, must be greater than min-size!");
}
});
// ctx.preparedLog = new PreparedLogFile(ctx, SwiftUtilities.addWorkingDir((String) ctx.xaEntity.getProperty("path").getValue()),
// ((Boolean) ctx.xaEntity.getProperty("force-sync").getValue()).booleanValue());
ctx.cacheManager = new CacheManager(ctx, ctx.stableStore, minCacheSize, maxCacheSize);
ctx.transactionManager = new TransactionManager(ctx);
ctx.logManager = createLogManagerFactory().createLogManager(ctx, ctx.transactionManager, SwiftUtilities.addWorkingDir((String) ctx.txEntity.getProperty("path").getValue()), ((Long) ctx.txEntity.getProperty("checkpoint-size").getValue()).longValue(), ((Boolean) ctx.txEntity.getProperty("force-sync").getValue()).booleanValue());
ctx.recoveryManager.restart(isRecoverOnStartup());
rootIndex = new RootIndex(ctx, 0);
ctx.preparedLog = new PreparedLogQueue(ctx, rootIndex.getQueueIndex(PREPARED_LOG_QUEUE));
ctx.backupProcessor = new BackupProcessor(ctx);
checkBackupPath();
ctx.shrinkProcessor = new ShrinkProcessor(ctx);
CommandRegistry commandRegistry = ctx.dbEntity.getCommandRegistry();
CommandExecutor shrinkExecutor = new CommandExecutor() {
public String[] execute(String[] context, Entity entity, String[] cmd) {
if (cmd.length != 1)
return new String[] { TreeCommands.ERROR, "Invalid command, please try 'shrink'" };
Semaphore sem = new Semaphore();
StartShrink po = new StartShrink(sem);
ctx.shrinkProcessor.enqueue(po);
sem.waitHere();
String[] result = null;
if (po.isSuccess())
result = new String[] { TreeCommands.INFO, "Shrink initiated." };
else
result = new String[] { TreeCommands.ERROR, po.getException() };
return result;
}
};
Command backupCommand = new Command("shrink", "shrink", "Perform Shrink Now", true, shrinkExecutor, true, false);
commandRegistry.addCommand(backupCommand);
SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent event) {
ctx.schedulerSwiftlet = (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler");
jobRegistrar = new JobRegistrar(ctx);
jobRegistrar.register();
}
public void swiftletStopInitiated(SwiftletManagerEvent event) {
jobRegistrar.unregister();
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace("sys$store", "startup...done");
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.getMessage());
}
}
use of com.swiftmq.swiftlet.event.SwiftletManagerAdapter in project swiftmq-ce by iitsoftware.
the class NetworkSwiftletImpl method startup.
@Override
protected void startup(Configuration config) throws SwiftletException {
try {
ctx = new SwiftletContext(config, this);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
setConnectionManager(new ConnectionManagerImpl(ctx));
ivmScheduler = new IntraVMScheduler(ctx);
ioScheduler = new NettyIOScheduler(ctx);
Property prop = config.getProperty("reuse-serversockets");
reuseServerSocket = (Boolean) prop.getValue();
prop = config.getProperty("dns-resolve-enabled");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
dnsResolve = (Boolean) newValue;
}
});
dnsResolve = (Boolean) prop.getValue();
prop = config.getProperty("zombi-connection-timeout");
zombiConnectionTimeout = (Long) prop.getValue();
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
zombiConnectionTimeout = (Long) newValue;
}
});
prop = config.getProperty("collect-interval");
prop.setPropertyChangeListener(new PropertyChangeAdapter(null) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
collectInterval = (Long) newValue;
collectChanged((Long) oldValue, collectInterval);
}
});
collectInterval = (Long) prop.getValue();
if (collectOn) {
if (collectInterval > 0) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: registering byte count collector");
ctx.timerSwiftlet.addTimerListener(collectInterval, this);
} else if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: collect interval <= 0; no byte count collector");
}
try {
SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering MgmtListener ...");
ctx.mgmtSwiftlet.addMgmtListener(new MgmtListener() {
public void adminToolActivated() {
collectOn = true;
collectChanged(-1, collectInterval);
}
public void adminToolDeactivated() {
collectChanged(collectInterval, -1);
collectOn = false;
}
});
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup DONE");
}
use of com.swiftmq.swiftlet.event.SwiftletManagerAdapter in project swiftmq-ce by iitsoftware.
the class MgmtSwiftletImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
ctx = new SwiftletContext(this, config);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
ctx.routingSwiftlet.addRoutingListener(ctx.dispatchQueue);
miController = new MessageInterfaceController(ctx);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$amqp", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
listener = new Listener(ctx);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done");
}
use of com.swiftmq.swiftlet.event.SwiftletManagerAdapter 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());
}
use of com.swiftmq.swiftlet.event.SwiftletManagerAdapter in project swiftmq-client by iitsoftware.
the class RouterMemoryMeter method start.
public synchronized void start() {
timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
if (mgmtSwiftlet != null)
mgmtSwiftlet.addMgmtListener(RouterMemoryMeter.this);
else {
SwiftletManager.getInstance().addSwiftletManagerListener("sys$mgmt", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
mgmtSwiftlet = (MgmtSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$mgmt");
mgmtSwiftlet.addMgmtListener(RouterMemoryMeter.this);
}
});
}
}
Aggregations