org.apache.qpid.proton.engine.EndpointState Java Examples
The following examples show how to use
org.apache.qpid.proton.engine.EndpointState.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void bind(Connection conn) { // TODO - check if already bound _connectionEndpoint = (ConnectionImpl) conn; put(Event.Type.CONNECTION_BOUND, conn); _connectionEndpoint.setTransport(this); _connectionEndpoint.incref(); if(getRemoteState() != EndpointState.UNINITIALIZED) { _connectionEndpoint.handleOpen(_open); if(getRemoteState() == EndpointState.CLOSED) { _connectionEndpoint.setRemoteState(EndpointState.CLOSED); } _frameParser.flush(); } }
Example #2
Source File: SenderImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public int sendNoCopy(final ReadableBuffer buffer) { if (getLocalState() == EndpointState.CLOSED) { throw new IllegalStateException("send not allowed after the sender is closed."); } DeliveryImpl current = current(); if (current == null || current.getLink() != this) { throw new IllegalArgumentException(); } int sent = current.sendNoCopy(buffer); if (sent > 0) { getSession().incrementOutgoingBytes(sent); } return sent; }
Example #3
Source File: SenderImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public int send(final ReadableBuffer buffer) { if (getLocalState() == EndpointState.CLOSED) { throw new IllegalStateException("send not allowed after the sender is closed."); } DeliveryImpl current = current(); if (current == null || current.getLink() != this) { throw new IllegalArgumentException(); } int sent = current.send(buffer); if (sent > 0) { getSession().incrementOutgoingBytes(sent); } return sent; }
Example #4
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void handleEnd(End end, Binary payload, Integer channel) { TransportSession transportSession = _remoteSessions.get(channel); if(transportSession == null) { // TODO - fail due to attach on non-begun session } else { _remoteSessions.remove(channel); transportSession.receivedEnd(); transportSession.unsetRemoteChannel(); SessionImpl session = transportSession.getSession(); session.setRemoteState(EndpointState.CLOSED); ErrorCondition errorCondition = end.getError(); if(errorCondition != null) { session.getRemoteCondition().copyFrom(errorCondition); } _connectionEndpoint.put(Event.Type.SESSION_REMOTE_CLOSE, session); } }
Example #5
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public void handleClose(Close close, Binary payload, Integer channel) { _closeReceived = true; _remoteIdleTimeout = 0; setRemoteState(EndpointState.CLOSED); if(_connectionEndpoint != null) { _connectionEndpoint.setRemoteState(EndpointState.CLOSED); if(close.getError() != null) { _connectionEndpoint.getRemoteCondition().copyFrom(close.getError()); } _connectionEndpoint.put(Event.Type.CONNECTION_REMOTE_CLOSE, _connectionEndpoint); } }
Example #6
Source File: SenderImpl.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Override public int send(final byte[] bytes, int offset, int length) { if (getLocalState() == EndpointState.CLOSED) { throw new IllegalStateException("send not allowed after the sender is closed."); } DeliveryImpl current = current(); if (current == null || current.getLink() != this) { throw new IllegalArgumentException();//TODO. } int sent = current.send(bytes, offset, length); if (sent > 0) { getSession().incrementOutgoingBytes(sent); } return sent; }
Example #7
Source File: SimpleTest.java From qpid-proton-j with Apache License 2.0 | 6 votes |
@Test public void test() { Connection connection1 = Proton.connection(); Connection connection2 = Proton.connection();; Transport transport1 = Proton.transport(); transport1.bind(connection1); Transport transport2 = Proton.transport(); transport2.bind(connection2); assertEquals(EndpointState.UNINITIALIZED, connection1.getLocalState()); assertEquals(EndpointState.UNINITIALIZED, connection1.getRemoteState()); connection1.open(); connection2.open(); }
Example #8
Source File: AmqpAbstractResource.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void detach(AsyncResult request) { // If already closed signal success or else the caller might never get notified. if (getEndpoint().getLocalState() == EndpointState.CLOSED || getEndpoint().getRemoteState() == EndpointState.CLOSED) { if (getEndpoint().getLocalState() != EndpointState.CLOSED) { doDetach(); getEndpoint().free(); } request.onSuccess(); } else { this.closeRequest = request; doDetach(); } }
Example #9
Source File: AmqpAbstractResource.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public void close(AsyncResult request) { // If already closed signal success or else the caller might never get notified. if (getEndpoint().getLocalState() == EndpointState.CLOSED || getEndpoint().getRemoteState() == EndpointState.CLOSED) { if (getEndpoint().getLocalState() != EndpointState.CLOSED) { doClose(); getEndpoint().free(); } request.onSuccess(); } else { this.closeRequest = request; doClose(); } }
Example #10
Source File: ProtonHandler.java From activemq-artemis with Apache License 2.0 | 6 votes |
public Long tick(boolean firstTick) { requireHandler(); if (!firstTick) { try { if (connection.getLocalState() != EndpointState.CLOSED) { long rescheduleAt = transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); if (transport.isClosed()) { throw new IllegalStateException("Channel was inactive for to long"); } return rescheduleAt; } } catch (Exception e) { log.warn(e.getMessage(), e); transport.close(); connection.setCondition(new ErrorCondition()); } finally { flush(); } return 0L; } return transport.tick(TimeUnit.NANOSECONDS.toMillis(System.nanoTime())); }
Example #11
Source File: ProtonServerSenderContext.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void executeDelivery(MessageReference messageReference) { try { if (sender.getLocalState() == EndpointState.CLOSED) { log.debug("Not delivering message " + messageReference + " as the sender is closed and credits were available, if you see too many of these it means clients are issuing credits and closing the connection with pending credits a lot of times"); return; } AMQPMessage message = CoreAmqpConverter.checkAMQP(messageReference.getMessage(), sessionSPI.getStorageManager()); if (sessionSPI.invokeOutgoing(message, (ActiveMQProtonRemotingConnection) sessionSPI.getTransportConnection().getProtocolConnection()) != null) { return; } if (message instanceof AMQPLargeMessage) { deliverLarge(messageReference, (AMQPLargeMessage) message); } else { deliverStandard(messageReference, message); } } catch (Exception e) { log.warn(e.getMessage(), e); brokerConsumer.errorProcessing(e, messageReference); } }
Example #12
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void processEnd() { if(_connectionEndpoint != null && _isOpenSent) { EndpointImpl endpoint = _connectionEndpoint.getTransportHead(); while(endpoint != null) { SessionImpl session; TransportSession transportSession; if((endpoint instanceof SessionImpl)) { if ((session = (SessionImpl)endpoint).getLocalState() == EndpointState.CLOSED && (transportSession = session.getTransportSession()).isLocalChannelSet() && !_isCloseSent) { if (hasSendableMessages(session)) { endpoint = endpoint.transportNext(); continue; } int channel = freeLocalChannel(transportSession); End end = new End(); ErrorCondition localError = endpoint.getCondition(); if( localError.getCondition() !=null ) { end.setError(localError); } writeFrame(channel, end, null, null); } endpoint.clearModified(); } endpoint = endpoint.transportNext(); } } }
Example #13
Source File: ConnectionImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public Link linkHead(EnumSet<EndpointState> local, EnumSet<EndpointState> remote) { if(_linkHead == null) { return null; } else { LinkNode.Query<LinkImpl> query = new EndpointImplQuery<LinkImpl>(local, remote); LinkNode<LinkImpl> node = query.matches(_linkHead) ? _linkHead : _linkHead.next(query); return node == null ? null : node.getValue(); } }
Example #14
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void processClose() { if ((_conditionSet || (_connectionEndpoint != null && _connectionEndpoint.getLocalState() == EndpointState.CLOSED)) && !_isCloseSent) { if(!hasSendableMessages(null)) { Close close = new Close(); ErrorCondition localError; if (_connectionEndpoint != null && isConditionPopulated(_connectionEndpoint.getCondition())) { localError = _connectionEndpoint.getCondition(); } else { // Connection is null or didn't have a condition set, use transport condition. localError = getCondition(); } if(isConditionPopulated(localError)) { close.setError(localError); } _isCloseSent = true; writeFrame(0, close, null, null); if (_connectionEndpoint != null) { _connectionEndpoint.clearModified(); } } } }
Example #15
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSessionRemoteClose(Event evt) { Session ssn = evt.getSession(); if (ssn.getLocalState() != EndpointState.CLOSED) { ssn.close(); } }
Example #16
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionRemoteOpen(Event evt) { Connection conn = evt.getConnection(); if (conn.getLocalState() == EndpointState.UNINITIALIZED) { conn.open(); } }
Example #17
Source File: Driver.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onConnectionLocalOpen(Event evt) { Connection conn = evt.getConnection(); if (conn.getRemoteState() == EndpointState.UNINITIALIZED) { // Give the connection a [random] container-id conn.setContainer(UUID.randomUUID().toString()); try { new Connector(conn); } catch (IOException e) { throw new RuntimeException(e); } } }
Example #18
Source File: TransportImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
/** * This method is public as it is used by Python layer. * @see org.apache.qpid.proton.engine.Transport#input(byte[], int, int) */ public TransportResult oldApiCheckStateBeforeInput(int inputLength) { _lastTransportResult.checkIsOk(); if(inputLength == 0) { if(_connectionEndpoint == null || _connectionEndpoint.getRemoteState() != EndpointState.CLOSED) { return TransportResultFactory.error(new TransportException("Unexpected EOS when remote connection not closed: connection aborted")); } } return TransportResultFactory.ok(); }
Example #19
Source File: EndpointImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void open() { if (getLocalState() != EndpointState.ACTIVE) { _localState = EndpointState.ACTIVE; localOpen(); modified(); } }
Example #20
Source File: EndpointImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void close() { if (getLocalState() != EndpointState.CLOSED) { _localState = EndpointState.CLOSED; localClose(); modified(); } }
Example #21
Source File: ConnectionImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public Session sessionHead(final EnumSet<EndpointState> local, final EnumSet<EndpointState> remote) { if(_sessionHead == null) { return null; } else { LinkNode.Query<SessionImpl> query = new EndpointImplQuery<SessionImpl>(local, remote); LinkNode<SessionImpl> node = query.matches(_sessionHead) ? _sessionHead : _sessionHead.next(query); return node == null ? null : node.getValue(); } }
Example #22
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onSessionRemoteOpen(Event evt) { Session ssn = evt.getSession(); if (ssn.getLocalState() == EndpointState.UNINITIALIZED) { ssn.open(); } }
Example #23
Source File: ConnectionImpl.java From qpid-proton-j with Apache License 2.0 | 5 votes |
void handleOpen(Open open) { // TODO - store state setRemoteState(EndpointState.ACTIVE); setRemoteHostname(open.getHostname()); setRemoteContainer(open.getContainerId()); setRemoteDesiredCapabilities(open.getDesiredCapabilities()); setRemoteOfferedCapabilities(open.getOfferedCapabilities()); setRemoteProperties(open.getProperties()); put(Event.Type.CONNECTION_REMOTE_OPEN, this); }
Example #24
Source File: Handshaker.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Override public void onLinkRemoteOpen(Event event) { Link link = event.getLink(); if (link.getLocalState() == EndpointState.UNINITIALIZED) { if (link.getRemoteSource() != null) { link.setSource(link.getRemoteSource().copy()); } if (link.getRemoteTarget() != null) { link.setTarget(link.getRemoteTarget().copy()); } } open(link); }
Example #25
Source File: IOHandler.java From qpid-proton-j with Apache License 2.0 | 5 votes |
private void handleOpen(Reactor reactor, Event event) { Connection connection = event.getConnection(); if (connection.getRemoteState() != EndpointState.UNINITIALIZED) { return; } // Outgoing Reactor connections set the virtual host automatically using the // following rules: String vhost = connection.getHostname(); if (vhost == null) { // setHostname never called, use the host from the connection's // socket address as the default virtual host: String conAddr = reactor.getConnectionAddress(connection); if (conAddr != null) { Address addr = new Address(conAddr); connection.setHostname(addr.getHost()); } } else if (vhost.isEmpty()) { // setHostname called explictly with a null string. This allows // the application to completely avoid sending a virtual host // name connection.setHostname(null); } else { // setHostname set by application - use it. } Transport transport = Proton.transport(); int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize(); if (maxFrameSizeOption != 0) { transport.setMaxFrameSize(maxFrameSizeOption); } if (reactor.getOptions().isEnableSaslByDefault()) { Sasl sasl = transport.sasl(); sasl.client(); sasl.setMechanisms("ANONYMOUS"); } transport.bind(connection); }
Example #26
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
/** * TODO it's not clear why empty input is specifically allowed in this case. */ @Test public void testEmptyInputWhenRemoteConnectionIsClosedUsingOldApi_isAllowed() { ConnectionImpl connection = new ConnectionImpl(); _transport.bind(connection); connection.setRemoteState(EndpointState.CLOSED); _transport.input(new byte [0], 0, 0); }
Example #27
Source File: TransportImplTest.java From qpid-proton-j with Apache License 2.0 | 5 votes |
@Test public void testTickLocalTimeout() { MockTransportImpl transport = new MockTransportImpl(); transport.setIdleTimeout(4000); Connection connection = Proton.connection(); transport.bind(connection); transport.handleFrame(TRANSPORT_FRAME_OPEN); connection.open(); pumpMockTransport(transport); long deadline = transport.tick(0); assertEquals("Expected to be returned a deadline of 4000", 4000, deadline); int framesWrittenBeforeTick = transport.writes.size(); deadline = transport.tick(1000); // Wait for less than the deadline with no data - get the same value assertEquals("When the deadline hasn't been reached tick() should return the previous deadline", 4000, deadline); assertEquals("Reading data should never result in a frame being written", 0, transport.writes.size() - framesWrittenBeforeTick); // Protocol header + empty frame ByteBuffer data = ByteBuffer.wrap(new byte[] {'A', 'M', 'Q', 'P', 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00, 0x00}); processInput(transport, data); framesWrittenBeforeTick = transport.writes.size(); deadline = transport.tick(2000); assertEquals("Reading data data resets the deadline", 6000, deadline); assertEquals("Reading data should never result in a frame being written", 0, transport.writes.size() - framesWrittenBeforeTick); assertEquals("Reading data before the deadline should keep the connection open", EndpointState.ACTIVE, connection.getLocalState()); framesWrittenBeforeTick = transport.writes.size(); deadline = transport.tick(7000); assertEquals("Calling tick() after the deadline should result in the connection being closed", EndpointState.CLOSED, connection.getLocalState()); }
Example #28
Source File: ProtonTransport.java From vertx-proton with Apache License 2.0 | 5 votes |
@Override public void handle(Long event) { boolean checkScheduled = false; if (connection.getLocalState() == EndpointState.ACTIVE) { // Using nano time since it is not related to the wall clock, which may change long now = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long deadline = transport.tick(now); try { flush(); } catch (IllegalStateException ex) { // socket closed already deadline = 0; } if (transport.isClosed()) { LOG.info("IdleTimeoutCheck closed the transport due to the peer exceeding our requested idle-timeout."); disconnect(); } else { if (deadline != 0) { // timer treats 0 as error, ensure value is at least 1 as there was a deadline long delay = Math.max(deadline - now, 1); checkScheduled = true; if (LOG.isTraceEnabled()) { LOG.trace("IdleTimeoutCheck rescheduling with delay: " + delay); } idleTimeoutCheckTimerId = vertx.setTimer(delay, this); } } } else { LOG.trace("IdleTimeoutCheck skipping check, connection is not active."); } if (!checkScheduled) { idleTimeoutCheckTimerId = null; LOG.trace("IdleTimeoutCheck exiting"); } }
Example #29
Source File: ProtonServerSenderContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * handle an out going message from ActiveMQ Artemis, send via the Proton Sender */ public int deliverMessage(final MessageReference messageReference, final ServerConsumer consumer) throws Exception { if (closed) { return 0; } try { synchronized (creditsLock) { if (sender.getLocalState() == EndpointState.CLOSED) { return 0; } pending.incrementAndGet(); credits--; } if (messageReference.getMessage() instanceof AMQPLargeMessage) { hasLarge = true; } if (messageReference instanceof Runnable && consumer.allowReferenceCallback()) { messageReference.onDelivery(executeDelivery); connection.runNow((Runnable) messageReference); } else { connection.runNow(() -> executeDelivery(messageReference)); } // This is because on AMQP we only send messages based in credits, not bytes return 1; } finally { } }
Example #30
Source File: ProtonServerSenderContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
public boolean hasCredits() { if (hasLarge) { // we will resume accepting once the large message is finished return false; } if (!connection.flowControl(onflowControlReady)) { return false; } synchronized (creditsLock) { return credits > 0 && sender.getLocalState() != EndpointState.CLOSED; } }