use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class AMQPHandler method visit.
public void visit(POSendOpen po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
Entity connectionTemplate = versionedConnection.getConnectionTemplate();
myIdleTimeout = ((Long) connectionTemplate.getProperty("idle-timeout").getValue()).longValue();
OpenFrame frame = new OpenFrame(0);
frame.setContainerId(new AMQPString(SwiftletManager.getInstance().getRouterName()));
frame.setChannelMax(new AMQPUnsignedShort(((Integer) connectionTemplate.getProperty("max-channel-number").getValue()).intValue()));
frame.setMaxFrameSize(new AMQPUnsignedInt(((Long) connectionTemplate.getProperty("max-frame-size").getValue()).longValue()));
try {
AMQPArray offeredCapas = new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPSymbol[] { new AMQPSymbol(CAPABILITY_NO_LOCAL), new AMQPSymbol(CAPABILITY_SELECTOR) });
frame.setOfferedCapabilities(offeredCapas);
} catch (IOException e) {
e.printStackTrace();
}
if (myIdleTimeout > 0) {
frame.setIdleTimeOut(new Milliseconds(myIdleTimeout));
idleTimeoutChecker = new TimerListener() {
public void performTimeAction() {
dispatch(new POCheckIdleTimeout(null));
}
};
ctx.timerSwiftlet.addTimerListener(myIdleTimeout / 2, idleTimeoutChecker);
}
versionedConnection.send(AMQPHandlerFactory.AMQP_INIT);
versionedConnection.send(frame);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class OutboundWriter method writeObject.
public void writeObject(Dumpable obj) {
if (closed)
return;
if (traceSpace.enabled)
traceSpace.trace("smqp", "write object: " + obj);
try {
Dumpalizer.dump(outStream, obj);
outStream.flush();
if (obj.getDumpId() == SMQPFactory.DID_DISCONNECT_REP) {
timerSwiftlet.addInstantTimerListener(10000, new TimerListener() {
public void performTimeAction() {
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
});
}
} catch (Exception e) {
if (traceSpace.enabled)
traceSpace.trace("smqp", "exception write object, exiting!: " + e);
// closes the connection
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
}
use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class OutboundWriter method writeObject.
public void writeObject(Dumpable obj) {
if (closed)
return;
if (traceSpace.enabled)
traceSpace.trace("smqp", "write object: " + obj);
try {
Dumpalizer.dump(outStream, obj);
outStream.flush();
if (obj.getDumpId() == SMQPFactory.DID_DISCONNECT_REP) {
timerSwiftlet.addInstantTimerListener(10000, new TimerListener() {
public void performTimeAction() {
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
});
}
} catch (Exception e) {
if (traceSpace.enabled)
traceSpace.trace("smqp", "exception write object, exiting!: " + e);
// closes the connection
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
}
use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class OutboundWriter method writeObject.
public void writeObject(Dumpable obj) {
if (closed)
return;
if (traceSpace.enabled)
traceSpace.trace("smqp", "write object: " + obj);
try {
Dumpalizer.dump(outStream, obj);
outStream.flush();
if (obj.getDumpId() == SMQPFactory.DID_DISCONNECT_REP) {
timerSwiftlet.addInstantTimerListener(10000, new TimerListener() {
public void performTimeAction() {
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
});
}
} catch (Exception e) {
if (traceSpace.enabled)
traceSpace.trace("smqp", "exception write object, exiting!: " + e);
// closes the connection
networkSwiftlet.getConnectionManager().removeConnection(connection);
outboundQueue.close();
closed = true;
}
}
use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class StreamController method restart.
public void restart() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/restart ...");
stop();
long restartDelay = (Long) entity.getProperty("restart-delay").getValue();
if (restartDelay > 0) {
long maxRestarts = (Integer) entity.getProperty("restart-max").getValue();
nRestarts++;
if (maxRestarts > nRestarts) {
ctx.timerSwiftlet.addInstantTimerListener(restartDelay, new TimerListener() {
@Override
public void performTimeAction() {
try {
if (enabled)
start();
} catch (Exception e) {
ctx.logSwiftlet.logError(toString(), "Exception restarting stream: " + e);
stop();
}
}
});
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/restart done");
}
Aggregations