use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class ChannelHandler method publishCurrentMessage.
private void publishCurrentMessage(Exchange exchange) {
if (exchange.getType() == Exchange.DIRECT) {
String rk = getMapping(currentMessage.getPublish().getRoutingKey());
QueueSender sender = (QueueSender) producers.get(rk);
try {
if (sender == null) {
if (producers.size() > 10) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", sender cache > 10, closing all");
for (Iterator iter = producers.entrySet().iterator(); iter.hasNext(); ) {
QueueSender s = (QueueSender) ((Map.Entry) iter.next()).getValue();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", closing sender for queue: " + s.getQueueName());
s.close();
iter.remove();
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", creating new sender on queue: " + rk);
sender = ctx.queueManager.createQueueSender(rk, versionedConnection.getActiveLogin());
producers.put(rk, sender);
}
QueuePushTransaction t = sender.createTransaction();
MessageImpl msg = inboundTransformer.transform(currentMessage, this);
msg.setJMSDestination(create(rk));
msg.reset();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", converted JMS message: " + msg);
t.putMessage(msg);
t.commit();
if (remoteFlowActive) {
long fcDelay = t.getFlowControlDelay();
if (fcDelay > 100) {
sendFlow(false);
ctx.timerSwiftlet.addInstantTimerListener(fcDelay, new TimerListener() {
public void performTimeAction() {
dispatch(PO_ACTIVATE_FLOW);
}
});
}
}
} catch (JMSException e) {
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.CHANNEL_ERROR, "Exception on publishing to exchange '" + currentMessage.getPublish().getExchange() + "': " + e, currentMessage.getPublish()));
}
} else
amqpHandler.dispatch(new POSendChannelClose(channelNo, Constants.NOT_IMPLEMENTED, "Exchange is not of type direct: " + currentMessage.getPublish().getExchange(), currentMessage.getPublish()));
}
use of com.swiftmq.swiftlet.timer.event.TimerListener in project swiftmq-ce by iitsoftware.
the class AMQPHandler method visit.
public void visit(POSendTune po) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
lastActivity = System.currentTimeMillis();
Tune tune = new Tune();
int channelMax = ((Integer) connectionTemplate.getProperty("max-channel-number").getValue()).intValue();
tune.setChannelMax(channelMax > Short.MAX_VALUE ? 0 : channelMax);
tune.setFrameMax(maxLocalFrameSize);
tune.setHeartbeat((int) (myIdleTimeout / 1000));
Frame frame = new Frame(Frame.TYPE_METHOD, 0, 0, null);
toPayload(frame, tune);
versionedConnection.send(frame);
if (myIdleTimeout > 0) {
idleTimeoutChecker = new TimerListener() {
public void performTimeAction() {
dispatch(new POCheckIdleTimeout(null));
}
};
ctx.timerSwiftlet.addTimerListener(myIdleTimeout + 5000, idleTimeoutChecker);
}
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 DispatchQueue method checkStartLeases.
private void checkStartLeases() {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/checkStartLeases, dispatchers.size(): " + dispatchers.size());
if (dispatchers.size() == 1) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(ctx.mgmtSwiftlet.getName(), toString() + "/checkStartLeases, start timers");
ctx.timerSwiftlet.addTimerListener(EXPIRATION_CHECK_INTERVAL, this);
updateTimer = new TimerListener() {
public void performTimeAction() {
pipelineQueue.enqueue(new SendUpdates());
}
};
Property prop = ctx.root.getProperty("flush-interval");
flushInterval = ((Long) prop.getValue()).longValue();
ctx.timerSwiftlet.addTimerListener(flushInterval, updateTimer);
prop.setPropertyChangeListener(new PropertyChangeListener() {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ctx.timerSwiftlet.removeTimerListener(updateTimer);
flushInterval = ((Long) newValue).longValue();
ctx.timerSwiftlet.addTimerListener(flushInterval, updateTimer);
}
});
RouterConfiguration.Singleton().addEntityWatchListener(this);
addWatchListeners(RouterConfiguration.Singleton());
ctx.mgmtSwiftlet.fireEvent(true);
leaseStarted = 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;
}
}
Aggregations