Package org.apache.activemq.command

Examples of org.apache.activemq.command.Command


     */
    public void run() {
        LOG.trace("Consumer thread starting for: " + toString());
        while (!isStopped()) {
            try {
                Command command = commandChannel.read();
                doConsume(command);
            } catch (AsynchronousCloseException e) {
                // DatagramChannel closed
                try {
                    stop();
View Full Code Here


    private void restoreTransactions(Transport transport, ConnectionState connectionState) throws IOException {
        for (Iterator iter = connectionState.getTransactionStates().iterator(); iter.hasNext();) {
            TransactionState transactionState = (TransactionState)iter.next();
            for (Iterator iterator = transactionState.getCommands().iterator(); iterator.hasNext();) {
                Command command = (Command)iterator.next();
                transport.oneway(command);
            }
        }
    }
View Full Code Here

            }
        });
        remoteBroker.setTransportListener(new DefaultTransportListener() {

            public void onCommand(Object o) {
                Command command = (Command)o;
                if (started.get()) {
                    serviceRemoteCommand(command);
                }
            }
View Full Code Here

        this.transport.setTransportListener(new DefaultTransportListener() {

            public void onCommand(Object o) {
                serviceLock.readLock().lock();
                try {
                    Command command = (Command)o;
                    Response response = service(command);
                    if (response != null) {
                        dispatchSync(response);
                    }
                } finally {
View Full Code Here

                }
                return false;
            }

            if (!dispatchStopped.get()) {
                Command command = null;
                synchronized(dispatchQueue) {
                    if (dispatchQueue.isEmpty()) {
                        return false;
                    }
                    command = dispatchQueue.remove(0);
View Full Code Here

        // Run the MessageDispatch callbacks so that message references get
        // cleaned up.
        synchronized(dispatchQueue) {
            for (Iterator<Command> iter = dispatchQueue.iterator(); iter.hasNext();) {
                Command command = iter.next();
                if (command.isMessageDispatch()) {
                    MessageDispatch md = (MessageDispatch)command;
                    Runnable sub = md.getTransmitCallback();
                    broker.postProcessDispatch(md);
                    if (sub != null) {
                        sub.run();
View Full Code Here

    }

    TransportListener createTransportListener() {
        return new TransportListener() {
            public void onCommand(Object o) {
                Command command = (Command)o;
                if (command == null) {
                    return;
                }
                if (command.isResponse()) {
                    Object object = null;
                    synchronized(requestMap) {
                     object = requestMap.remove(Integer.valueOf(((Response)command).getCorrelationId()));
                    }
                    if (object != null && object.getClass() == Tracked.class) {
                        ((Tracked)object).onResponses();
                    }
                }
                if (!initialized) {
                    if (command.isBrokerInfo()) {
                        BrokerInfo info = (BrokerInfo)command;
                        BrokerInfo[] peers = info.getPeerBrokerInfos();
                        if (peers != null) {
                            for (int i = 0; i < peers.length; i++) {
                                String brokerString = peers[i].getBrokerURL();
View Full Code Here

    }
  

    public void oneway(Object o) throws IOException {
       
        Command command = (Command)o;
        Exception error = null;
        try {

            synchronized (reconnectMutex) {
                if (isShutdownCommand(command) && connectedTransport.get() == null) {
                    if(command.isShutdownInfo()) {
                        // Skipping send of ShutdownInfo command when not connected.
                        return;
                    }
                    if(command instanceof RemoveInfo) {
                        // Simulate response to RemoveInfo command
                        Response response = new Response();
                        response.setCorrelationId(command.getCommandId());
                        myTransportListener.onCommand(response);
                        return;
                    }
                }                     
                // Keep trying until the message is sent.
                for (int i = 0; !disposed; i++) {
                    try {

                        // Wait for transport to be connected.
                        Transport transport = connectedTransport.get();
                        while (transport == null && !disposed
                                && connectionFailure == null
                                && !Thread.currentThread().isInterrupted()) {
                            LOG.trace("Waiting for transport to reconnect.");
                            try {
                                reconnectMutex.wait(1000);
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                                LOG.debug("Interupted: " + e, e);
                            }
                            transport = connectedTransport.get();
                        }

                        if (transport == null) {
                            // Previous loop may have exited due to use being
                            // disposed.
                            if (disposed) {
                                error = new IOException("Transport disposed.");
                            } else if (connectionFailure != null) {
                                error = connectionFailure;
                            } else {
                                error = new IOException("Unexpected failure.");
                            }
                            break;
                        }

                        // If it was a request and it was not being tracked by
                        // the state tracker,
                        // then hold it in the requestMap so that we can replay
                        // it later.
                        Tracked tracked = stateTracker.track(command);
                        synchronized(requestMap) {
                            if (tracked != null && tracked.isWaitingForResponse()) {
                                requestMap.put(Integer.valueOf(command.getCommandId()), tracked);
                            } else if (tracked == null && command.isResponseRequired()) {
                                requestMap.put(Integer.valueOf(command.getCommandId()), command);
                            }
                        }

                        // Send the message.
                        try {
                            transport.oneway(command);
                            stateTracker.trackBack(command);
                        } catch (IOException e) {

                            // If the command was not tracked.. we will retry in
                            // this method
                            if (tracked == null) {

                                // since we will retry in this method.. take it
                                // out of the request
                                // map so that it is not sent 2 times on
                                // recovery
                                if (command.isResponseRequired()) {
                                    requestMap.remove(Integer.valueOf(command.getCommandId()));
                                }

                                // Rethrow the exception so it will handled by
                                // the outer catch
                                throw e;
View Full Code Here

        this.protocolConverter = new ProtocolConverter(this, translator, applicationContext);
    }

    public void oneway(Object o) throws IOException {
        try {
            final Command command = (Command)o;
            protocolConverter.onActiveMQCommad(command);
        } catch (JMSException e) {
            throw IOExceptionSupport.create(e);
        }
    }
View Full Code Here

        Map tmpMap = null;
        synchronized(requestMap) {
            tmpMap = new LinkedHashMap<Integer, Command>(requestMap);
        }
        for (Iterator<Command> iter2 = tmpMap.values().iterator(); iter2.hasNext();) {
            Command command = iter2.next();
            t.oneway(command);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.command.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.