use of org.apache.qpid.proton.engine.Event in project activemq-artemis by apache.
the class ProtonHandler method dispatch.
private void dispatch() {
Event ev;
lock.lock();
try {
if (inDispatch) {
// Avoid recursion from events
return;
}
try {
inDispatch = true;
while ((ev = collector.peek()) != null) {
for (EventHandler h : handlers) {
if (log.isTraceEnabled()) {
log.trace("Handling " + ev + " towards " + h);
}
try {
Events.dispatch(ev, h);
} catch (Exception e) {
log.warn(e.getMessage(), e);
ErrorCondition error = new ErrorCondition();
error.setCondition(AmqpError.INTERNAL_ERROR);
error.setDescription("Unrecoverable error: " + (e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage()));
connection.setCondition(error);
connection.close();
}
}
collector.pop();
}
} finally {
inDispatch = false;
}
} finally {
lock.unlock();
}
flushBytes();
}
use of org.apache.qpid.proton.engine.Event in project activemq-artemis by apache.
the class AmqpConnection method processUpdates.
private void processUpdates() {
try {
Event protonEvent = null;
while ((protonEvent = protonCollector.peek()) != null) {
if (!protonEvent.getType().equals(Type.TRANSPORT)) {
LOG.trace("Client: New Proton Event: {}", protonEvent.getType());
}
AmqpEventSink amqpEventSink = null;
switch(protonEvent.getType()) {
case CONNECTION_REMOTE_CLOSE:
amqpEventSink = (AmqpEventSink) protonEvent.getConnection().getContext();
amqpEventSink.processRemoteClose(this);
break;
case CONNECTION_REMOTE_OPEN:
amqpEventSink = (AmqpEventSink) protonEvent.getConnection().getContext();
amqpEventSink.processRemoteOpen(this);
break;
case SESSION_REMOTE_CLOSE:
amqpEventSink = (AmqpEventSink) protonEvent.getSession().getContext();
amqpEventSink.processRemoteClose(this);
break;
case SESSION_REMOTE_OPEN:
amqpEventSink = (AmqpEventSink) protonEvent.getSession().getContext();
amqpEventSink.processRemoteOpen(this);
break;
case LINK_REMOTE_CLOSE:
amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext();
amqpEventSink.processRemoteClose(this);
break;
case LINK_REMOTE_DETACH:
amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext();
amqpEventSink.processRemoteDetach(this);
break;
case LINK_REMOTE_OPEN:
amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext();
amqpEventSink.processRemoteOpen(this);
break;
case LINK_FLOW:
amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext();
amqpEventSink.processFlowUpdates(this);
break;
case DELIVERY:
amqpEventSink = (AmqpEventSink) protonEvent.getLink().getContext();
amqpEventSink.processDeliveryUpdates(this, (Delivery) protonEvent.getContext());
break;
default:
break;
}
protonCollector.pop();
}
// We have to do this to pump SASL bytes in as SASL is not event driven yet.
if (!authenticated) {
processSaslAuthentication();
}
} catch (Exception ex) {
LOG.warn("Caught Exception during update processing: {}", ex.getMessage(), ex);
fireClientException(ex);
}
}
use of org.apache.qpid.proton.engine.Event in project vertx-proton by vert-x3.
the class ProtonTransport method handleSocketBuffer.
private void handleSocketBuffer(Buffer buff) {
pumpInbound(buff);
if (!failed) {
processSaslAuthentication();
}
Event protonEvent = null;
while ((protonEvent = collector.peek()) != null) {
ProtonConnectionImpl conn = (ProtonConnectionImpl) protonEvent.getConnection().getContext();
Type eventType = protonEvent.getType();
if (LOG.isTraceEnabled() && !eventType.equals(Type.TRANSPORT)) {
LOG.trace("New Proton Event: " + eventType);
}
switch(eventType) {
case CONNECTION_REMOTE_OPEN:
{
conn.fireRemoteOpen();
initiateIdleTimeoutChecks();
break;
}
case CONNECTION_REMOTE_CLOSE:
{
conn.fireRemoteClose();
break;
}
case SESSION_REMOTE_OPEN:
{
ProtonSessionImpl session = (ProtonSessionImpl) protonEvent.getSession().getContext();
if (session == null) {
conn.fireRemoteSessionOpen(protonEvent.getSession());
} else {
session.fireRemoteOpen();
}
break;
}
case SESSION_REMOTE_CLOSE:
{
ProtonSessionImpl session = (ProtonSessionImpl) protonEvent.getSession().getContext();
session.fireRemoteClose();
break;
}
case LINK_REMOTE_OPEN:
{
ProtonLinkImpl<?> link = (ProtonLinkImpl<?>) protonEvent.getLink().getContext();
if (link == null) {
conn.fireRemoteLinkOpen(protonEvent.getLink());
} else {
link.fireRemoteOpen();
}
break;
}
case LINK_REMOTE_DETACH:
{
ProtonLinkImpl<?> link = (ProtonLinkImpl<?>) protonEvent.getLink().getContext();
link.fireRemoteDetach();
break;
}
case LINK_REMOTE_CLOSE:
{
ProtonLinkImpl<?> link = (ProtonLinkImpl<?>) protonEvent.getLink().getContext();
link.fireRemoteClose();
break;
}
case LINK_FLOW:
{
ProtonLinkImpl<?> link = (ProtonLinkImpl<?>) protonEvent.getLink().getContext();
link.handleLinkFlow();
break;
}
case DELIVERY:
{
ProtonDeliveryImpl delivery = (ProtonDeliveryImpl) protonEvent.getDelivery().getContext();
if (delivery != null) {
delivery.fireUpdate();
} else {
ProtonReceiverImpl receiver = (ProtonReceiverImpl) protonEvent.getLink().getContext();
receiver.onDelivery();
}
break;
}
case TRANSPORT_ERROR:
{
failed = true;
break;
}
case CONNECTION_INIT:
case CONNECTION_BOUND:
case CONNECTION_UNBOUND:
case CONNECTION_LOCAL_OPEN:
case CONNECTION_LOCAL_CLOSE:
case CONNECTION_FINAL:
case SESSION_INIT:
case SESSION_LOCAL_OPEN:
case SESSION_LOCAL_CLOSE:
case SESSION_FINAL:
case LINK_INIT:
case LINK_LOCAL_OPEN:
case LINK_LOCAL_DETACH:
case LINK_LOCAL_CLOSE:
case LINK_FINAL:
}
collector.pop();
}
flush();
if (failed) {
disconnect();
}
}
Aggregations