Package org.fusesource.hawtdispatch.transport

Examples of org.fusesource.hawtdispatch.transport.Transport


    /**
     * Creates a client transport.
     */
    public static Transport connect(String location) throws Exception {
        for( Provider provider : providers.jsingletons()) {
          Transport rc = provider.connect(location);
          if( rc!=null ) {
            return rc;
          }
        }
        throw new IllegalArgumentException("Unknown transport connect uri: "+location);
View Full Code Here


  }
 
    @Ignore
  @Test()
  public void autoCreateBroker() throws Exception {
    Transport connect = TransportFactory.connect("vm://test1");
        connect.setDispatchQueue(Dispatch.createQueue());
        RunnableCountDownLatch cd = new RunnableCountDownLatch(1);
        connect.start(cd);
        cd.await();
    assertNotNull(connect);
        cd = new RunnableCountDownLatch(1);
    connect.stop(cd);
        cd.await();
  }
View Full Code Here

            // Cleanup the previous transport.
            if(heartBeatMonitor!=null) {
                heartBeatMonitor.stop();
                heartBeatMonitor = null;
            }
            final Transport t = transport;
            transport = null;

            if(t!=null) {
                t.stop(new Task() {
                    @Override
                    public void run() {
                        listener.onDisconnected();
                        reconnect();
                    }
View Full Code Here

     */
    void createTransport(final Callback<Transport> onConnect) throws Exception {
        mqtt.tracer.debug("Connecting");
        String scheme = mqtt.host.getScheme();

        final Transport transport;
        if( "tcp".equals(scheme) ) {
            transport = new TcpTransport();
        else if( SslTransport.protocol(scheme)!=null ) {
            SslTransport ssl = new SslTransport();
            if( mqtt.sslContext == null ) {
                mqtt.sslContext = SSLContext.getDefault();
            }
            ssl.setSSLContext(mqtt.sslContext);
            transport = ssl;
        } else {
            throw new Exception("Unsupported URI scheme '"+scheme+"'");
        }

        if( mqtt.blockingExecutor == null ) {
            mqtt.blockingExecutor = MQTT.getBlockingThreadPool();
        }
        transport.setBlockingExecutor(mqtt.blockingExecutor);
        transport.setDispatchQueue(queue);
        transport.setProtocolCodec(new MQTTProtocolCodec());

        if( transport instanceof TcpTransport ) {
            TcpTransport tcp = (TcpTransport)transport;
            tcp.setMaxReadRate(mqtt.maxReadRate);
            tcp.setMaxWriteRate(mqtt.maxWriteRate);
            tcp.setReceiveBufferSize(mqtt.receiveBufferSize);
            tcp.setSendBufferSize(mqtt.sendBufferSize);
            tcp.setTrafficClass(mqtt.trafficClass);
            tcp.setUseLocalHost(mqtt.useLocalHost);
            tcp.connecting(mqtt.host, mqtt.localAddress);
        }

        transport.setTransportListener(new DefaultTransportListener(){
            @Override
            public void onTransportConnected() {
                mqtt.tracer.debug("Transport connected");
                if(disconnected) {
                    onFailure(createDisconnectedError());
                } else {
                    onConnect.onSuccess(transport);
                }
            }

            @Override
            public void onTransportFailure(final IOException error) {
                mqtt.tracer.debug("Transport failure: %s", error);
                onFailure(error);
            }

            private void onFailure(final Throwable error) {
                if(!transport.isClosed()) {
                    transport.stop(new Task() {
                        @Override
                        public void run() {
                            onConnect.onFailure(error);
                        }
                    });
                }
            }
        });
        transport.start(NOOP);
    }
View Full Code Here

TOP

Related Classes of org.fusesource.hawtdispatch.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.