protonConnection.open();
write();
}
//handle any new sessions
Session session = protonConnection.sessionHead(ProtonProtocolManager.UNINITIALIZED, ProtonProtocolManager.INITIALIZED);
while (session != null)
{
try
{
ProtonSession protonSession = getSession(session);
session.setContext(protonSession);
session.open();
}
catch (HornetQAMQPException e)
{
protonConnection.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
session.close();
}
write();
session = protonConnection.sessionHead(ProtonProtocolManager.UNINITIALIZED, ProtonProtocolManager.INITIALIZED);
}
//handle new link (producer or consumer
LinkImpl link = (LinkImpl) protonConnection.linkHead(ProtonProtocolManager.UNINITIALIZED, ProtonProtocolManager.INITIALIZED);
while (link != null)
{
try
{
protonProtocolManager.handleNewLink(link, getSession(link.getSession()));
}
catch (HornetQAMQPException e)
{
link.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
link.close();
}
link = (LinkImpl) protonConnection.linkHead(ProtonProtocolManager.UNINITIALIZED, ProtonProtocolManager.INITIALIZED);
}
//handle any deliveries
DeliveryImpl delivery;
Iterator<DeliveryImpl> iterator = protonConnection.getWorkSequence();
while (iterator.hasNext())
{
delivery = iterator.next();
ProtonDeliveryHandler handler = (ProtonDeliveryHandler) delivery.getLink().getContext();
try
{
handler.onMessage(delivery);
}
catch (HornetQAMQPException e)
{
delivery.getLink().setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
}
}
link = (LinkImpl) protonConnection.linkHead(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.ANY_ENDPOINT_STATE);
while (link != null)
{
try
{
protonProtocolManager.handleActiveLink(link);
}
catch (HornetQAMQPException e)
{
link.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
}
link = (LinkImpl) link.next(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.ANY_ENDPOINT_STATE);
}
link = (LinkImpl) protonConnection.linkHead(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.CLOSED);
while (link != null)
{
try
{
((ProtonDeliveryHandler) link.getContext()).close();
}
catch (HornetQAMQPException e)
{
link.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
}
link.close();
link = (LinkImpl) link.next(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.CLOSED);
}
session = protonConnection.sessionHead(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.CLOSED);
while (session != null)
{
ProtonSession protonSession = (ProtonSession) session.getContext();
protonSession.close();
sessions.remove(session);
session.close();
session = session.next(ProtonProtocolManager.ACTIVE, ProtonProtocolManager.CLOSED);
}
if (protonConnection.getLocalState() == EndpointState.ACTIVE && protonConnection.getRemoteState() == EndpointState.CLOSED)
{
for (ProtonSession protonSession : sessions.values())