use of org.apache.qpid.protonj2.client.SessionOptions in project qpid-protonj2 by apache.
the class ClientConnection method openStreamSender.
@Override
public StreamSender openStreamSender(String address, StreamSenderOptions senderOptions) throws ClientException {
checkClosedOrFailed();
Objects.requireNonNull(address, "Cannot create a sender with a null address");
final ClientFuture<StreamSender> createRequest = getFutureFactory().createFuture();
executor.execute(() -> {
try {
int sessionCapacity = StreamSenderOptions.DEFAULT_PENDING_WRITES_BUFFER_SIZE;
if (senderOptions != null) {
sessionCapacity = senderOptions.pendingWritesBufferSize();
}
// Session capacity cannot be smaller than one frame size so we adjust to the lower bound
sessionCapacity = (int) Math.max(sessionCapacity, protonConnection.getMaxFrameSize());
checkClosedOrFailed();
SessionOptions sessionOptions = new SessionOptions(sessionBuilder.getDefaultSessionOptions());
ClientStreamSession session = (ClientStreamSession) sessionBuilder.streamSession(sessionOptions.outgoingCapacity(sessionCapacity)).open();
createRequest.complete(session.internalOpenStreamSender(address, senderOptions));
} catch (Throwable error) {
createRequest.failed(ClientExceptionSupport.createNonFatalOrPassthrough(error));
}
});
return request(this, createRequest);
}
use of org.apache.qpid.protonj2.client.SessionOptions in project qpid-protonj2 by apache.
the class ClientConnection method openStreamReceiver.
@Override
public StreamReceiver openStreamReceiver(String address, StreamReceiverOptions receiverOptions) throws ClientException {
checkClosedOrFailed();
final ClientFuture<StreamReceiver> createRequest = getFutureFactory().createFuture();
executor.execute(() -> {
try {
int sessionCapacity = StreamReceiverOptions.DEFAULT_READ_BUFFER_SIZE;
if (receiverOptions != null) {
sessionCapacity = receiverOptions.readBufferSize() / 2;
}
// Session capacity cannot be smaller than one frame size so we adjust to the lower bound
sessionCapacity = (int) Math.max(sessionCapacity, protonConnection.getMaxFrameSize());
checkClosedOrFailed();
SessionOptions sessionOptions = new SessionOptions(sessionBuilder.getDefaultSessionOptions());
ClientStreamSession session = (ClientStreamSession) sessionBuilder.streamSession(sessionOptions.incomingCapacity(sessionCapacity)).open();
createRequest.complete(session.internalOpenStreamReceiver(address, receiverOptions));
} catch (Throwable error) {
createRequest.failed(ClientExceptionSupport.createNonFatalOrPassthrough(error));
}
});
return request(this, createRequest);
}
use of org.apache.qpid.protonj2.client.SessionOptions in project qpid-protonj2 by apache.
the class SessionTest method doTestSessionCloseTimeoutWhenNoRemoteEndArrives.
private void doTestSessionCloseTimeoutWhenNoRemoteEndArrives(boolean timeout) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin().respond();
peer.expectEnd();
peer.expectClose().respond();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
SessionOptions options = new SessionOptions();
options.closeTimeout(75);
Session session = connection.openSession(options).openFuture().get();
try {
if (timeout) {
session.closeAsync().get(10, TimeUnit.SECONDS);
} else {
session.closeAsync().get();
}
fail("Close should throw an error if the Session end doesn't arrive in time");
} catch (Throwable error) {
LOG.info("Session close failed with error: ", error);
}
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.SessionOptions in project qpid-protonj2 by apache.
the class SessionTest method tryReadSessionRemoteProperties.
private void tryReadSessionRemoteProperties(boolean beginResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
SessionOptions options = new SessionOptions().openTimeout(120, TimeUnit.MILLISECONDS);
Session session = connection.openSession(options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
Map<String, Object> expectedProperties = new HashMap<>();
expectedProperties.put("TEST", "test-property");
if (beginResponse) {
peer.expectEnd().respond();
peer.respondToLastBegin().withProperties(expectedProperties).later(10);
} else {
peer.expectEnd();
}
if (beginResponse) {
assertNotNull(session.properties(), "Remote should have responded with a remote properties value");
assertEquals(expectedProperties, session.properties());
} else {
try {
session.properties();
fail("Should failed to get remote state due to no begin response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
session.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and end was sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
use of org.apache.qpid.protonj2.client.SessionOptions in project qpid-protonj2 by apache.
the class SessionTest method tryReadSessionRemoteOfferedCapabilities.
private void tryReadSessionRemoteOfferedCapabilities(boolean beginResponse) throws Exception {
try (ProtonTestServer peer = new ProtonTestServer()) {
peer.expectSASLAnonymousConnect();
peer.expectOpen().respond();
peer.expectBegin();
peer.start();
URI remoteURI = peer.getServerURI();
LOG.info("Connect test started, peer listening on: {}", remoteURI);
Client container = Client.create();
Connection connection = container.connect(remoteURI.getHost(), remoteURI.getPort());
connection.openFuture().get();
SessionOptions options = new SessionOptions().openTimeout(125);
Session session = connection.openSession(options);
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
if (beginResponse) {
peer.expectEnd().respond();
peer.respondToLastBegin().withOfferedCapabilities("transactions").later(10);
} else {
peer.expectEnd();
}
if (beginResponse) {
assertNotNull(session.offeredCapabilities(), "Remote should have responded with a remote offered Capabilities value");
assertEquals(1, session.offeredCapabilities().length);
assertEquals("transactions", session.offeredCapabilities()[0]);
} else {
try {
session.offeredCapabilities();
fail("Should failed to get remote state due to no begin response");
} catch (ClientException ex) {
LOG.debug("Caught expected exception from blocking call", ex);
}
}
try {
session.closeAsync().get();
} catch (ExecutionException ex) {
LOG.debug("Caught unexpected exception from close call", ex);
fail("Should not fail to close when connection not closed and end was sent");
}
peer.expectClose().respond();
connection.closeAsync().get();
peer.waitForScriptToComplete(5, TimeUnit.SECONDS);
}
}
Aggregations