public void run() { try { List<InterHubMessage> messages = new ArrayList<InterHubMessage>(); try { while (true) { lock.lock(); try { queue.take(messages); } finally { lock.unlock(); } for (InterHubMessage message : messages) { connection.dispatch(message); if (message instanceof EndOfStream) { connection.flush(); return; } } connection.flush(); messages.clear(); } } finally { lock.lock(); try { connectionState.dispatchFinished(); } finally { lock.unlock(); } } } catch (Throwable t) { errorHandler.execute(t); } }
public void run() { try { try { while (true) { InterHubMessage message = connection.receive(); if (message == null || message instanceof EndOfStream) { return; } lock.lock(); try { incomingQueue.queue(message); } finally { lock.unlock(); } } } finally { lock.lock(); try { connectionState.receiveFinished(); } finally { lock.unlock(); } } } catch (Throwable e) { errorHandler.execute(e); } }
private ConnectionDispatch(ConnectionState connectionState) { this.connection = connectionState.getConnection(); this.queue = connectionState.getDispatchQueue(); this.connectionState = connectionState; }
public ConnectionReceive(ConnectionState connectionState) { this.connection = connectionState.getConnection(); this.connectionState = connectionState; }