use of org.apache.activemq.command.Command in project activemq-artemis by apache.
the class OpenWireConnection method disconnect.
private void disconnect(ActiveMQException me, String reason, boolean fail) {
if (context == null || destroyed) {
return;
}
// Don't allow things to be added to the connection state while we
// are shutting down.
// is it necessary? even, do we need state at all?
state.shutdown();
// Then call the listeners
// this should closes underlying sessions
callFailureListeners(me);
// this should clean up temp dests
callClosingListeners();
destroyed = true;
// before closing transport, sendCommand the last response if any
Command command = context.getLastCommand();
if (command != null && command.isResponseRequired()) {
Response lastResponse = new Response();
lastResponse.setCorrelationId(command.getCommandId());
try {
dispatchSync(lastResponse);
} catch (Throwable e) {
ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
}
}
}
use of org.apache.activemq.command.Command in project activemq-artemis by apache.
the class OpenWireConnection method bufferReceived.
@Override
public void bufferReceived(Object connectionID, ActiveMQBuffer buffer) {
super.bufferReceived(connectionID, buffer);
try {
recoverOperationContext();
Command command = (Command) inWireFormat.unmarshal(buffer);
// log the openwire command
if (logger.isTraceEnabled()) {
traceBufferReceived(connectionID, command);
}
boolean responseRequired = command.isResponseRequired();
int commandId = command.getCommandId();
// ignore pings
if (command.getClass() != KeepAliveInfo.class) {
Response response = null;
try {
setLastCommand(command);
response = command.visit(commandProcessorInstance);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.warn("Errors occurred during the buffering operation ", e);
if (responseRequired) {
response = convertException(e);
}
} finally {
setLastCommand(null);
}
if (response instanceof ExceptionResponse) {
Throwable cause = ((ExceptionResponse) response).getException();
if (!responseRequired) {
serviceException(cause);
response = null;
}
// stop the connection to prevent dangling sockets
if (command instanceof ConnectionInfo) {
delayedStop(2000, cause.getMessage(), cause);
}
}
if (responseRequired) {
if (response == null) {
response = new Response();
response.setCorrelationId(commandId);
}
}
// sent.
if (context != null) {
if (context.isDontSendReponse()) {
context.setDontSendReponse(false);
response = null;
}
}
sendAsyncResponse(commandId, response);
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.debug(e);
sendException(e);
} finally {
clearupOperationContext();
}
}
use of org.apache.activemq.command.Command in project activemq-artemis by apache.
the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.
@Test
public void TestOptimizedDispatchCME() throws Exception {
final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
final ConnectionContext contextNotInTx = new ConnectionContext();
contextNotInTx.setConnection(new Connection() {
@Override
public void stop() throws Exception {
}
@Override
public void start() throws Exception {
}
@Override
public void updateClient(ConnectionControl control) {
}
@Override
public void serviceExceptionAsync(IOException e) {
}
@Override
public void serviceException(Throwable error) {
}
@Override
public Response service(Command command) {
return null;
}
@Override
public boolean isSlow() {
return false;
}
@Override
public boolean isNetworkConnection() {
return false;
}
@Override
public boolean isManageable() {
return false;
}
@Override
public boolean isFaultTolerantConnection() {
return false;
}
@Override
public boolean isConnected() {
return true;
}
@Override
public boolean isBlocked() {
return false;
}
@Override
public boolean isActive() {
return false;
}
@Override
public ConnectionStatistics getStatistics() {
return null;
}
@Override
public String getRemoteAddress() {
return null;
}
@Override
public int getDispatchQueueSize() {
return 0;
}
@Override
public Connector getConnector() {
// TODO Auto-generated method stub
return null;
}
@Override
public String getConnectionId() {
return null;
}
@Override
public void dispatchSync(Command message) {
}
@Override
public void dispatchAsync(Command command) {
}
@Override
public int getActiveTransactionCount() {
return 0;
}
@Override
public Long getOldestActiveTransactionDuration() {
return null;
}
});
final DestinationStatistics destinationStatistics = new DestinationStatistics();
final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
final MockMemoryUsage usage = new MockMemoryUsage();
queue.setOptimizedDispatch(true);
queue.initialize();
queue.start();
queue.memoryUsage = usage;
ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
ProducerInfo producerInfo = new ProducerInfo();
ProducerState producerState = new ProducerState(producerInfo);
producerExchange.setProducerState(producerState);
producerExchange.setConnectionContext(contextNotInTx);
// populate the queue store, exceed memory limit so that cache is disabled
for (int i = 0; i < count; i++) {
Message message = getMessage(i);
queue.send(producerExchange, message);
}
usage.setFull(false);
try {
queue.wakeup();
} catch (Exception e) {
LOG.error("Queue threw an unexpected exception: " + e.toString());
fail("Should not throw an exception.");
}
}
use of org.apache.activemq.command.Command in project activemq-artemis by apache.
the class UdpTestSupport method testSendingSmallMessage.
public void testSendingSmallMessage() throws Exception {
ConsumerInfo expected = new ConsumerInfo();
expected.setSelector("Cheese");
expected.setExclusive(true);
expected.setExclusive(true);
expected.setPrefetchSize(3456);
try {
LOG.info("About to send: " + expected);
producer.oneway(expected);
Command received = assertCommandReceived();
assertTrue("Should have received a ConsumerInfo but was: " + received, received instanceof ConsumerInfo);
ConsumerInfo actual = (ConsumerInfo) received;
assertEquals("Selector", expected.getSelector(), actual.getSelector());
assertEquals("isExclusive", expected.isExclusive(), actual.isExclusive());
assertEquals("getPrefetchSize", expected.getPrefetchSize(), actual.getPrefetchSize());
} catch (Exception e) {
LOG.info("Caught: " + e);
e.printStackTrace();
fail("Failed to send to transport: " + e);
}
}
use of org.apache.activemq.command.Command in project activemq-artemis by apache.
the class UdpTestSupport method assertSendTextMessage.
protected void assertSendTextMessage(ActiveMQDestination destination, String text) throws MessageNotWriteableException {
large = true;
ActiveMQTextMessage expected = new ActiveMQTextMessage();
expected.setText(text);
expected.setDestination(destination);
try {
LOG.info("About to send message of type: " + expected.getClass());
producer.oneway(expected);
// lets send a dummy command to ensure things don't block if we
// discard the last one
// keepalive does not have a commandId...
// producer.oneway(new KeepAliveInfo());
producer.oneway(new ProducerInfo());
producer.oneway(new ProducerInfo());
Command received = assertCommandReceived();
assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
assertEquals("getDestination", expected.getDestination(), actual.getDestination());
assertEquals("getText", expected.getText(), actual.getText());
LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
} catch (Exception e) {
LOG.info("Caught: " + e);
e.printStackTrace();
fail("Failed to send to transport: " + e);
}
}
Aggregations