Package org.apache.activemq.command

Examples of org.apache.activemq.command.Command


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

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


    public void start() throws Exception {
        if (started.compareAndSet(false, true)) {
            localBroker.setTransportListener(new DefaultTransportListener() {

                public void onCommand(Object o) {
                    Command command = (Command)o;
                    serviceLocalCommand(command);
                }

                public void onException(IOException error) {
                    serviceLocalException(error);
                }
            });
            remoteBroker.setTransportListener(new TransportListener() {

                public void onCommand(Object o) {
                    Command command = (Command)o;
                    serviceRemoteCommand(command);
                }

                public void onException(IOException error) {
                    serviceRemoteException(error);
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 = 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 setRandomize(boolean randomize) {
        this.randomize = randomize;
    }

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

            synchronized (reconnectMutex) {
                // Keep trying until the message is sent.
                for (int i = 0; !disposed; i++) {
                    try {

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

                        if (connectedTransport == 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);
                        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 {
                            connectedTransport.oneway(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

    protected void restoreTransport(Transport t) throws Exception, IOException {
        t.start();
        stateTracker.restore(t);
        for (Iterator<Command> iter2 = requestMap.values().iterator(); iter2.hasNext();) {
            Command command = iter2.next();
            t.oneway(command);
        }
    }
View Full Code Here

        super(next);
        this.sequenceGenerator = sequenceGenerator;
    }

    public void oneway(Object o) throws IOException {
        Command command = (Command)o;
        command.setCommandId(sequenceGenerator.getNextSequenceId());
        command.setResponseRequired(false);
        next.oneway(command);
    }
View Full Code Here

        command.setResponseRequired(false);
        next.oneway(command);
    }

    public FutureResponse asyncRequest(Object o, ResponseCallback responseCallback) throws IOException {
        Command command = (Command)o;
        command.setCommandId(sequenceGenerator.getNextSequenceId());
        command.setResponseRequired(true);
        FutureResponse future = new FutureResponse(responseCallback);
        synchronized (requestMap) {
            requestMap.put(new Integer(command.getCommandId()), future);
        }
        next.oneway(command);
        return future;
    }
View Full Code Here

        FutureResponse response = asyncRequest(command, null);
        return response.getResult(timeout);
    }

    public void onCommand(Object o) {
        Command command = (Command)o;
        if (command.isResponse()) {
            Response response = (Response)command;
            FutureResponse future = null;
            synchronized (requestMap) {
                future = requestMap.remove(Integer.valueOf(response.getCorrelationId()));
            }
View Full Code Here

        connector.setBrokerName(broker.getBrokerName());
        this.transport = transport;
        this.transport.setTransportListener(new DefaultTransportListener() {

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

            if (!dispatchStopped.get()) {

                if (dispatchQueue.isEmpty()) {
                    return false;
                }
                Command command = dispatchQueue.remove(0);
                processDispatch(command);
                return true;
            }
            return false;
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.