Package org.apache.activemq.transport

Examples of org.apache.activemq.transport.Transport


public class FailoverTransportFactory extends TransportFactory {

    public Transport doConnect(URI location) throws IOException {
        try {
            Transport transport = createTransport(URISupport.parseComposite(location));
            transport = new MutexTransport(transport);
            transport = new ResponseCorrelator(transport);
            return transport;
        } catch (URISyntaxException e) {
            throw new IOException("Invalid location: " + location);
View Full Code Here


                        URI uri = fanoutHandler.uri;
                        try {
                            LOG.debug("Stopped: " + this);
                            LOG.debug("Attempting connect to: " + uri);
                            Transport t = TransportFactory.compositeConnect(uri);
                            LOG.debug("Connection established");
                            fanoutHandler.transport = t;
                            fanoutHandler.reconnectDelay = 10;
                            fanoutHandler.connectFailures = 0;
                            if (primary == null) {
                                primary = fanoutHandler;
                            }
                            t.setTransportListener(fanoutHandler);
                            if (started) {
                                restoreTransport(fanoutHandler);
                            }
                            connectedCount++;
                        } catch (Exception e) {
View Full Code Here

import org.apache.activemq.util.URISupport.CompositeData;

public class MockTransportFactory extends TransportFactory {

    public Transport doConnect(URI location) throws URISyntaxException, Exception {
        Transport transport = createTransport(URISupport.parseComposite(location));
        transport = new MutexTransport(transport);
        transport = new ResponseCorrelator(transport);
        return transport;
    }
View Full Code Here

                        options.put("dynamicManagement", Boolean.valueOf(dynamicManagement));
                        options.put("startLogging", Boolean.valueOf(startLogging));

                        options.putAll(transportOptions);
                        WireFormat format = wireFormatFactory.createWireFormat();
                        Transport transport = createTransport(socket, format);
                        Transport configuredTransport = transportFactory.serverConfigure(transport, format, options);
                        getAcceptListener().onAccept(configuredTransport);
                    }
                }
            } catch (SocketTimeoutException ste) {
                // expect this to happen
View Full Code Here

        });

        // Configure the transport with any additional properties or filters.  Although the returned transport is not explicitly
        // persisted, if it is a filter (e.g., InactivityMonitor) it will be linked to the client's transport as a TransportListener
        // and not GC'd until the client's transport is disposed.
        Transport transport = answer;
        try {
            // Preserve the transportOptions for future use by making a copy before applying (they are removed when applied).
            HashMap options = new HashMap(transportOptions);
            transport = transportFactory.serverConfigure(answer, null, options);
        } catch (Exception e) {
            IOExceptionSupport.create(e);
        }

        // Wait for the transport to be connected or disposed.
        listener.onAccept(transport);
        while (!transport.isConnected() && !transport.isDisposed()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignore) {
            }
        }

        // Ensure that the transport was not prematurely disposed.
        if (transport.isDisposed()) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "The session for clientID '" + clientID + "' was prematurely disposed");
            LOG.warn("The session for clientID '" + clientID + "' was prematurely disposed");
            return null;
        }
View Full Code Here

                URI uri = broker.getVmConnectorURI();
                HashMap<String, String> map = new HashMap<String, String>(URISupport.parseParameters(uri));
                map.put("network", "true");
                map.put("async", "false");
                uri = URISupport.createURIWithQuery(uri, URISupport.createQueryString(map));
                Transport localTransport = TransportFactory.connect(uri);
                Transport remoteBridgeTransport = new ResponseCorrelator(transport);
                duplexBridge = NetworkBridgeFactory.createBridge(config, localTransport, remoteBridgeTransport);
                duplexBridge.setBrokerService(broker.getBrokerService());
                // now turn duplex off this side
                info.setDuplexConnection(false);
                duplexBridge.setCreatedByDuplex(true);
View Full Code Here

                    localConnectionInfo.setConnectionId(new ConnectionId(idGenerator.generateId()));
                    localClientId = "NC_" + remoteBrokerName + "_inbound_" + configuration.getBrokerName();
                    localConnectionInfo.setClientId(localClientId);
                    localConnectionInfo.setUserName(configuration.getUserName());
                    localConnectionInfo.setPassword(configuration.getPassword());
                    Transport originalTransport = remoteBroker;
                    while (originalTransport instanceof TransportFilter) {
                        originalTransport = ((TransportFilter) originalTransport).getNext();
                    }
                    if (originalTransport instanceof SslTransport) {
                        X509Certificate[] peerCerts = ((SslTransport) originalTransport).getPeerCertificates();
View Full Code Here

    public final void handleTransportFailure(IOException e) throws InterruptedException {
        if (LOG.isTraceEnabled()) {
            LOG.trace(this + " handleTransportFailure: " + e);
        }
        Transport transport = connectedTransport.getAndSet(null);
        if (transport == null) {
            // sync with possible in progress reconnect
            synchronized (reconnectMutex) {
                transport = connectedTransport.getAndSet(null);
            }
        }
        if (transport != null) {

            transport.setTransportListener(disposedListener);
            ServiceSupport.dispose(transport);

            boolean reconnectOk = false;
            synchronized (reconnectMutex) {
                if (started) {
                    LOG.warn("Transport (" + transport.getRemoteAddress() + ") failed to " + connectedTransportURI
                            + " , attempting to automatically reconnect due to: " + e);
                    LOG.debug("Transport failed with the following exception:", e);
                    reconnectOk = true;
                }
                initialized = false;
View Full Code Here

            }
        }
    }

    public void stop() throws Exception {
        Transport transportToStop = null;
        synchronized (reconnectMutex) {
            LOG.debug("Stopped.");
            if (!started) {
                return;
            }
            started = false;
            disposed = true;
            connected = false;
            for (BackupTransport t : backups) {
                t.setDisposed(true);
            }
            backups.clear();

            if (connectedTransport.get() != null) {
                transportToStop = connectedTransport.getAndSet(null);
            }
            reconnectMutex.notifyAll();
        }
        synchronized (sleepMutex) {
            sleepMutex.notifyAll();
        }
        reconnectTask.shutdown();
        if (transportToStop != null) {
            transportToStop.stop();
        }
    }
View Full Code Here

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

                        // Wait for transport to be connected.
                        Transport transport = connectedTransport.get();
                        long start = System.currentTimeMillis();
                        boolean timedout = false;
                        while (transport == null && !disposed && connectionFailure == null
                                && !Thread.currentThread().isInterrupted()) {
                            LOG.trace("Waiting for transport to reconnect..: " + command);
                            long end = System.currentTimeMillis();
                            if (timeout > 0 && (end - start > timeout)) {
                                timedout = true;
                                LOG.info("Failover timed out after " + (end - start) + "ms");
                                break;
                            }
                            try {
                                reconnectMutex.wait(100);
                            } 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 if (timedout == true) {
                                error = new IOException("Failover timeout of " + timeout + " ms reached.");
                            } 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
View Full Code Here

TOP

Related Classes of org.apache.activemq.transport.Transport

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.