本文整理匯總了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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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);
}