當前位置: 首頁>>代碼示例>>Java>>正文


Java ConnectFuture.getSession方法代碼示例

本文整理匯總了Java中org.apache.mina.core.future.ConnectFuture.getSession方法的典型用法代碼示例。如果您正苦於以下問題:Java ConnectFuture.getSession方法的具體用法?Java ConnectFuture.getSession怎麽用?Java ConnectFuture.getSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.mina.core.future.ConnectFuture的用法示例。


在下文中一共展示了ConnectFuture.getSession方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
@Override
public boolean start() {
    super.start();
    isAutoReConn = true;
    if (isRunning()) {
        return false;
    }

    init(config);
    ConnectFuture future = connector.connect();
    future.awaitUninterruptibly();
    try {
        mSession = future.getSession();
    } catch (Exception e) {
        onStartFailed(e);
        return false;
    }

    onStartSuccess();
    return true;
    //return mSession == null ? false : true;
}
 
開發者ID:EthanCo,項目名稱:Halo-Turbo,代碼行數:23,代碼來源:MinaTcpClientSocket.java

示例2: openConnection

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
private void openConnection() {
    if (this.address == null || !this.configuration.isCachedAddress()) {
        setSocketAddress(this.configuration.getProtocol());
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating connector to address: {} using connector: {} timeout: {} millis.", new Object[]{address, connector, timeout});
    }
    // connect and wait until the connection is established
    if (connectorConfig != null) {
        connector.getSessionConfig().setAll(connectorConfig);
    }

    connector.setHandler(new ResponseHandler());
    ConnectFuture future = connector.connect(address);
    future.awaitUninterruptibly();
    session = future.getSession();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:Mina2Producer.java

示例3: getSession

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
@Override
public IoSession getSession() throws SyslogSenderException {
    if (session == null || !session.isConnected()) {
        synchronized (this) {
            LOG.debug("Lazily open connection to address: {} using connector: {}", socketAddress, connector);
            // connect and wait until the connection is established
            if (connectorConfig != null) {
                connector.getSessionConfig().setAll(connectorConfig);
            }
            connector.setHandler(new ResponseHandler());
            ConnectFuture future = connector.connect(socketAddress);
            future.awaitUninterruptibly();
            try {
                session = future.getSession();
                if (session == null) {
                    throw new SyslogSenderException("Could not establish connection to " + socketAddress);
                }
            } catch (RuntimeException e) {
                throw new SyslogSenderException("Could not establish connection to " + socketAddress, e);
            }
        }
    }

    return session;
}
 
開發者ID:oehf,項目名稱:ipf-oht-atna,代碼行數:26,代碼來源:MinaTLSSyslogSenderImpl.java

示例4: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
/**
 * Attempt to connect to the info server.
 */
public void connect()
{
	try
	{
		ConnectFuture future = connector.connect(new InetSocketAddress(IP, PORT));
		future.awaitUninterruptibly(AWAIT_TIME);

		IoSession session = future.getSession();
		session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(factory));
		state = State.READY;
		this.onConnect(session);
	}
	catch(RuntimeIoException e)
	{
		this.onFailure(e);
	}
}
 
開發者ID:grahamedgecombe,項目名稱:opencraft,代碼行數:21,代碼來源:OCClient.java

示例5: main

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public static void main(String[] args) {
	NioSocketConnector connector = new NioSocketConnector(); //TCP Connector
	connector.getFilterChain().addLast("logging", new LoggingFilter());
	connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	connector.setHandler(new HelloClientHandler());
    IoSession session;

    for (;;) {
        try {
            ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT));
            future.awaitUninterruptibly();
            session = future.getSession();
            break;
        } catch (RuntimeIoException e) {
            System.err.println("Failed to connect.");
            e.printStackTrace();
        }
    }
    session.getCloseFuture().awaitUninterruptibly();
    connector.dispose();
}
 
開發者ID:ameizi,項目名稱:mina-examples,代碼行數:23,代碼來源:HelloTcpClient.java

示例6: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
/**
 * connects to a LLRP device at the host address and port specified. the connect method waits
 * for the timeperiod specified (in ms) for a response. If the READER_NOTIFICATION does not arrive 
 * or the ConnectionAttemptEventStatus 
 * is not set to 'Success', a LLRPConnectionAttemptFailedException is thrown.
 * 
 * @param timeout time in ms
 * @throws LLRPConnectionAttemptFailedException
 */

public void connect(long timeout) throws LLRPConnectionAttemptFailedException{
	connector = new NioSocketConnector();
	connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new LLRPProtocolCodecFactory(LLRPProtocolCodecFactory.BINARY_ENCODING)));
	// MINA 2.0 method 
	connector.setHandler(handler);
	remoteAddress = new InetSocketAddress(host, port);
	ConnectFuture future = connector.connect(remoteAddress);//.connect(remoteAddress,handler);
	future.join();// Wait until the connection attempt is finished.
	
	if(future.isConnected()){
		session = future.getSession();
	}else{
		String msg = "failed to connect";
		throw new LLRPConnectionAttemptFailedException(msg);
	}
	// MINA 2.0
	//future.awaitUninterruptibly();
	
	//check if llrp reader reply with a status report to indicate connection success.
	//the client shall not send any information to the reader until this status report message is received
	checkLLRPConnectionAttemptStatus(timeout);
	
}
 
開發者ID:gs1oliot,項目名稱:oliot-fc,代碼行數:34,代碼來源:LLRPConnector.java

示例7: buildConnection

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public void buildConnection() {
	NioSocketConnector connector = new NioSocketConnector();
	connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(MessageCodecFactory.getInstance()));
	connector.setHandler(new ClientHandler());

	System.out.println("開始連接socket服務端"); 
	int serverPort = ServerConfig.getInstance().getServerPort();
	ConnectFuture future = connector.connect(new InetSocketAddress(serverPort));

	future.awaitUninterruptibly();

	IoSession session = future.getSession();
	this.session = session;

}
 
開發者ID:kingston-csj,項目名稱:jforgame,代碼行數:16,代碼來源:SocketRobot.java

示例8: main

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public static void main(String[] args) {
	IoConnector connector = new NioSocketConnector();
	connector.getFilterChain().addLast("logger", new LoggingFilter());
	connector.getFilterChain().addLast("codec",
			new ProtocolCodecFilter(new PrefixedStringCodecFactory(Charset.forName("UTF-8"))));
	connector.setHandler(new TimeClientHander());
	ConnectFuture connectFuture = connector.connect(new InetSocketAddress("127.0.0.1", PORT));
	// 等待建立連接
	connectFuture.awaitUninterruptibly();
	System.out.println("連接成功");
	IoSession session = connectFuture.getSession();
	Scanner sc = new Scanner(System.in);
	boolean quit = false;
	while (!quit) {
		String str = sc.next();
		if (str.equalsIgnoreCase("quit")) {
			quit = true;
		}
		session.write(str);
	}

	// 關閉
	if (session != null) {
		if (session.isConnected()) {
			session.getCloseFuture().awaitUninterruptibly();
		}
		connector.dispose(true);
	}

}
 
開發者ID:handexing,項目名稱:frameworkAggregate,代碼行數:31,代碼來源:MimaTimeClient.java

示例9: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public Cube connect() throws Exception {
    ConnectFuture future = connector.connect(new InetSocketAddress(hostname, port));
    future.awaitUninterruptibly();
    session = future.getSession();
    handler.awaitAndReset();
    return (Cube) session.getAttribute(CUBE);
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:8,代碼來源:MinaCubeClient.java

示例10: createClient

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
  if (isDebugEnabled) {
    LOGGER.debug("create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key);
  }
  if (connectTimeout > 1000) {
    ioConnector.setConnectTimeoutMillis((int) connectTimeout);
  } else {
    ioConnector.setConnectTimeoutMillis(1000);
  }
  SocketAddress targetAddress = new InetSocketAddress(targetIP, targetPort);
  MinaClientProcessor processor = new MinaClientProcessor(this, key);
  ioConnector.setHandler(processor);
  ConnectFuture connectFuture = ioConnector.connect(targetAddress);
  // wait for connection established
  connectFuture.awaitUninterruptibly();

  IoSession ioSession = connectFuture.getSession();
  if ((ioSession == null) || (!ioSession.isConnected())) {
    String targetUrl = targetIP + ":" + targetPort;
    LOGGER.error("create connection error,targetaddress is " + targetUrl);
    throw new Exception("create connection error,targetaddress is " + targetUrl);
  }
  if (isDebugEnabled) {
    LOGGER.debug(
        "create connection to :" + targetIP + ":" + targetPort + ",timeout is:" + connectTimeout + ",key is:" + key + " successed");
  }
  MinaClient client = new MinaClient(ioSession, key, connectTimeout);
  processor.setClient(client);
  return client;
}
 
開發者ID:leeyazhou,項目名稱:nfs-rpc,代碼行數:31,代碼來源:MinaClientFactory.java

示例11: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
/**
 * �����ͻ�������
 */
public boolean connect() {
	// ʵ���� �������� Socket����
	client = new NioSocketConnector();
	// �������ݹ�����
	DefaultIoFilterChainBuilder filterChain = client.getFilterChain();
	//filterChain.addLast("textCode", new ProtocolCodecFilter(
	//		new TextLineCodecFactory(Charset.forName("UTF-8"))));
	filterChain.addLast("myChin", new ProtocolCodecFilter(
			new ObjectSerializationCodecFactory()));
	// �ͻ��˴������
	ClientIoHandler clientIoHandler = new ClientIoHandler(loginFrame,client);
	client.setHandler(clientIoHandler);
	clientIoHandler.setRegisterFrame(registerFrame);
	// ���ӷ�����
	ConnectFuture future = client.connect(new InetSocketAddress(
			IP, Port));
	// �ȴ�
	future.awaitUninterruptibly();
	// �õ��Ự����
	try {
		session = future.getSession();
		return true;
	} catch (Exception e) {
		Tools.show(loginFrame, "�޷����ӷ�������������û������");
		client.dispose();
		if(registerFrame!=null)
		registerFrame.dispose();
		return false;
	}
	// session.getCloseFuture().awaitUninterruptibly();

}
 
開發者ID:ganhang,項目名稱:My-ChatSystem,代碼行數:36,代碼來源:Client.java

示例12: doStart

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
@Override
protected void doStart() throws Exception {
    super.doStart();
    if (configuration.isClientMode() && configuration.getProtocol().equals("tcp")) {
        connector.setHandler(new ReceiveHandler());
        ConnectFuture future = connector.connect(address);
        future.awaitUninterruptibly();
        session = future.getSession();
        LOG.info("Connected to server address: {} using connector: {} timeout: {} millis.", new Object[]{address, connector, configuration.getTimeout()});
    } else {
        acceptor.setHandler(new ReceiveHandler());
        acceptor.bind(address);
        LOG.info("Bound to server address: {} using acceptor: {}", address, acceptor);
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:16,代碼來源:Mina2Consumer.java

示例13: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public IoSession connect() throws Exception {
	ConnectFuture future = connector.connect(new InetSocketAddress((String)rule.get("ip"), (Integer)rule.get("port")));
	future.awaitUninterruptibly();
	/*boolean b = future.awaitUninterruptibly(cfg.getConTimeout());
	// 若返回值b==true,則表示設置了ConnectFuture的value,即調用了ConnectFuture的setException、setSession或cancel方法
	if (!b)
		throw new CommunicateException("連接遠程Tcp服務器超時");*/
	
	if (!future.isConnected())
		// 即getValue() instanceof IoSession == false,也就是說出現異常或Canceled
		throw new Exception("與遠程Tcp服務器建立連接失敗:超時或異常",
				future.getException());
	return future.getSession();
}
 
開發者ID:dreajay,項目名稱:jcode,代碼行數:15,代碼來源:TcpConnector.java

示例14: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public void connect() {
	ConnectFuture connectFuture = connector.connect(new InetSocketAddress(
			host, port));
	connectFuture.awaitUninterruptibly(CONNECT_TIMEOUT);
	try {
		session = connectFuture.getSession();
	} catch (RuntimeIoException e) {
		LOGGER.warn(e.getMessage(), e);
	}
}
 
開發者ID:jptiancai,項目名稱:TetrisMina,代碼行數:11,代碼來源:TetrisClient.java

示例15: connect

import org.apache.mina.core.future.ConnectFuture; //導入方法依賴的package包/類
public MessageSession connect(SocketAddress address) throws IOException {
	Objects.requireNonNull(address);

	// client session
	ConnectFuture connectFuture = connector.connect(address);
	connectFuture.awaitUninterruptibly();
	if (!connectFuture.isConnected() || connectFuture.getException() != null)
		throw new IOException("Connection error", connectFuture.getException());
	
	IoSession minaSession = connectFuture.getSession();
	return minaAdapter.getMessageSession(minaSession);
}
 
開發者ID:ugcs,項目名稱:ugcs-java-sdk,代碼行數:13,代碼來源:MinaConnector.java


注:本文中的org.apache.mina.core.future.ConnectFuture.getSession方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。