当前位置: 首页>>代码示例>>Java>>正文


Java WriteFuture类代码示例

本文整理汇总了Java中org.apache.mina.common.WriteFuture的典型用法代码示例。如果您正苦于以下问题:Java WriteFuture类的具体用法?Java WriteFuture怎么用?Java WriteFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WriteFuture类属于org.apache.mina.common包,在下文中一共展示了WriteFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
    super.send(message, sent);
    
    boolean success = true;
    int timeout = 0;
    try {
        WriteFuture future = session.write(message);
        if (sent) {
            timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
            success = future.join(timeout);
        }
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }
    
    if(!success) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
                + "in timeout(" + timeout + "ms) limit");
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:MinaChannel.java

示例2: send

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
    if (isClosed()) {
        throw new RemotingException(this, "Failed to send message "
                + (message == null ? "" : message.getClass().getName()) + ":" + message
                + ", cause: Channel closed. channel: " + getLocalAddress() + " -> " + getRemoteAddress());
    }
    boolean success = true;
    int timeout = 0;
    try {
        WriteFuture future = session.write(message);
        if (sent) {
            timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
            success = future.join(timeout);
        }
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }

    if(!success) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
                + "in timeout(" + timeout + "ms) limit");
    }
}
 
开发者ID:xyp260466,项目名称:dubbo-lite,代码行数:24,代码来源:MinaChannel.java

示例3: send

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void send(Object message, boolean sent) throws RemotingException {
    super.send(message, sent);

    boolean success = true;
    int timeout = 0;
    try {
        WriteFuture future = session.write(message);
        if (sent) {
            timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
            success = future.join(timeout);
        }
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }

    if (!success) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress()
                + "in timeout(" + timeout + "ms) limit");
    }
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:21,代码来源:MinaChannel.java

示例4: write

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
@Override
public WriteFuture write(Object o) {
    try {
        writeLock.lock();
        if (throwExceptionOnNextWrite) {
            throw new RuntimeException();
        }
        DefaultWriteFuture f = new DefaultWriteFuture(this);
        f.setWritten(!closed);
        if (!closed) {
            written.add(o);
            if (latch != null) {
                latch.countDown();
            }
        }
        return f;
    }
    finally {
        writeLock.unlock();
    }
}
 
开发者ID:betfair,项目名称:cougar,代码行数:22,代码来源:MyIoSession.java

示例5: write

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
@Override
public WriteFuture write(Object message) {
    DefaultWriteFuture ret = new DefaultWriteFuture(this);
    try {
        otherEnd.messageReceived(nextFilter, otherSession, message);
        ret.setWritten(true);
    }
    catch (Exception e) {
        e.printStackTrace();
        ret.setWritten(false);
    }
    // behave like the real thing..
    if (attributes.get(SSLFilter.DISABLE_ENCRYPTION_ONCE) != null) {
        attributes.remove(SSLFilter.DISABLE_ENCRYPTION_ONCE);
    }
    return ret;
}
 
开发者ID:betfair,项目名称:cougar,代码行数:18,代码来源:CougarProtocolTest.java

示例6: sendRequest

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void sendRequest(final RequestWrapper wrapper, final int timeout) throws Exception {
  final long beginTime = System.currentTimeMillis();
  WriteFuture writeFuture = session.write(wrapper);
  final Client self = this;
  writeFuture.addListener(new IoFutureListener() {
    public void operationComplete(IoFuture future) {
      WriteFuture wfuture = (WriteFuture) future;
      if (wfuture.isWritten()) {
        return;
      }
      String error = "send message to server: " + session.getRemoteAddress()
          + " error,maybe because sendbuffer is full or connection closed: " + !session.isConnected();
      if (System.currentTimeMillis() - beginTime >= timeout) {
        error = "write message to os send buffer timeout,consumetime is: " + (System.currentTimeMillis() - beginTime) + "ms,timeout is:"
            + timeout;
      }
      LOGGER.error(error);
      ResponseWrapper response = new ResponseWrapper(wrapper.getId(), wrapper.getCodecType(), wrapper.getProtocolType());
      response.setException(new Exception(error));
      try {
        putResponse(response);
      } catch (Exception e) {
        // IGNORE, should not happen
      }
      if (session.isConnected()) {
        if (isWarnEnabled) {
          LOGGER.warn("close the session because send request error,server:" + session.getRemoteAddress());
        }
        session.close();
      } else {
        // TODO: exception handle
        MinaClientFactory.getInstance().removeClient(key, self);
      }
    }
  });
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:37,代码来源:MinaClient.java

示例7: sendErrorResponse

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
private void sendErrorResponse(final IoSession session, final RequestWrapper request) {
  ResponseWrapper responseWrapper = new ResponseWrapper(request.getId(), request.getCodecType(), request.getProtocolType());
  responseWrapper.setException(new Exception("server threadpool full,maybe because server is slow or too many requests"));
  WriteFuture wf = session.write(responseWrapper);
  wf.addListener(new IoFutureListener() {
    public void operationComplete(IoFuture future) {
      if (!((WriteFuture) future).isWritten()) {
        LOGGER.error("server write response error,request id is: " + request.getId());
      }
    }
  });
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:13,代码来源:MinaServerHandler.java

示例8: run

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public void run() {
  // pipeline
  if (message instanceof List) {
    List messages = (List) message;
    for (Object messageObject : messages) {
      threadPool.execute(new HandlerRunnable(session, messageObject, threadPool));
    }
  } else {
    RequestWrapper request = (RequestWrapper) message;
    long beginTime = System.currentTimeMillis();
    ResponseWrapper responseWrapper = ProtocolFactory.getServerHandler(request.getProtocolType()).handleRequest(request);
    final int id = request.getId();
    // already timeout,so not return
    if ((System.currentTimeMillis() - beginTime) >= request.getTimeout()) {
      LOGGER.warn("timeout,so give up send response to client,requestId is:" + id + ",client is:" + session.getRemoteAddress()
          + ",consumetime is:" + (System.currentTimeMillis() - beginTime) + ",timeout is:" + request.getTimeout());
      return;
    }
    WriteFuture wf = session.write(responseWrapper);
    wf.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture future) {
        if (!((WriteFuture) future).isWritten()) {
          LOGGER.error("server write response error,request id is: " + id);
        }
      }
    });
  }
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:30,代码来源:MinaServerHandler.java

示例9: invokeAsync

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void invokeAsync(final BasePacket packet, final long timeout,ResponseListener listener){
	if(isDebugEnabled){
		LOGGER.debug("send request ["+packet.getChid()+"] async,time is:"+System.currentTimeMillis());
	}
	if(minTimeout>timeout){
		minTimeout=timeout;
	}
	final ResponseCallbackTask callbackTask=new ResponseCallbackTask(packet.getChid(),listener, this.session, timeout);
	callbackTasks.put(packet.getChid(), callbackTask);
	
	ByteBuffer bb = packet.getByteBuffer();
	bb.flip();
	byte[] data = new byte[bb.remaining()];
	bb.get(data);
	WriteFuture writeFuture=session.write(data);
	writeFuture.addListener(new IoFutureListener(){

		public void operationComplete(IoFuture future) {
			WriteFuture wfuture=(WriteFuture)future;
			if(wfuture.isWritten()){
				return;
			}
			String error = "send message to tair server error [" + packet.getChid() + "], tair server: " + session.getRemoteAddress()+", maybe because this connection closed :"+ !session.isConnected();
            LOGGER.warn(error);
            callbackTask.setResponse(new TairClientException(error));
            
			// close this session
			if(session.isConnected())
				session.close();
			else
				clientFactory.removeClient(key);
		}
		
	});
}
 
开发者ID:alibaba,项目名称:tair-java-client,代码行数:36,代码来源:TairClient.java

示例10: writeBody

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
/**
 * Asynchronously writes the given body to MINA session. Will wait at most for
 * 10 seconds until the body has been written.
 *
 * @param session  the MINA session
 * @param body     the body to write (send)
 * @param exchange the exchange
 * @throws CamelExchangeException is thrown if the body could not be written for some reasons
 *                                (eg remote connection is closed etc.)
 */
public static void writeBody(IoSession session, Object body, Exchange exchange) throws CamelExchangeException {
    // the write operation is asynchronous. Use WriteFuture to wait until the session has been written
    WriteFuture future = session.write(body);
    // must use a timeout (we use 10s) as in some very high performance scenarios a write can cause 
    // thread hanging forever
    LOG.trace("Waiting for write to complete for body: {} using session: {}", body, session);
    future.join(10000L);
    if (!future.isWritten()) {
        throw new CamelExchangeException("Cannot write body: " + body + " using session: " + session, exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MinaHelper.java

示例11: toggleCustomBGState

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public void toggleCustomBGState() {
    getQuestNAdd(MapleQuest.getInstance(CUSTOM_BG)).setCustomData(String.valueOf(getCustomBGState() == 1 ? 0 : 1));
    for (byte i = 0; i < 127; i++) {
        WriteFuture write = client.getSession().write(CField.removeBGLayer((getCustomBGState() == 1), 0, i, 0));
        //duration 0 = forever map 0 = current map
    }
}
 
开发者ID:skorch37,项目名称:Asteria,代码行数:8,代码来源:MapleCharacter.java

示例12: newSession

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
public static IoSession newSession(byte version) {
    final IoSession mockSession = mock(IoSession.class);
    when(mockSession.getAttribute(CougarProtocol.PROTOCOL_VERSION_ATTR_NAME)).thenReturn(version);
    final WriteFuture mockFuture = mock(WriteFuture.class);
    when(mockSession.write(any())).thenReturn(mockFuture);
    return mockSession;
}
 
开发者ID:betfair,项目名称:cougar,代码行数:8,代码来源:SessionTestUtil.java

示例13: write

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
@Override
public WriteFuture write(Object message) {
    allValuesWritten.add(message);
    DefaultWriteFuture future = new DefaultWriteFuture(this);
    future.setWritten(true);
    return future;
}
 
开发者ID:betfair,项目名称:cougar,代码行数:8,代码来源:MyIoSession.java

示例14: send

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
/**
 * Send a message with logging when trace enabled.
 * 
 * @param session The IO session.
 * @param serverDomain The server domain.
 * @param message The message.
 * 
 * @return The IO future.
 */
public static WriteFuture send (IoSession session, String serverDomain,
                                Message message)
{
  if (shouldLog (TRACE))
  {
    trace ("Federation session " + idFor (session) + " sent " + 
           message.name (), Federation.class);    }
  
  return session.write (message);
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:20,代码来源:Federation.java

示例15: send

import org.apache.mina.common.WriteFuture; //导入依赖的package包/类
private static WriteFuture send (IoSession session, Message message)
{    
  if (shouldLog (TRACE))
  {
    trace ("Server sent message to " + Text.idFor (session) + ": " + message,
           Router.class);
  }
  
  return session.write (message);
}
 
开发者ID:luv,项目名称:avis_zmqprx,代码行数:11,代码来源:Router.java


注:本文中的org.apache.mina.common.WriteFuture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。