本文整理汇总了Java中org.glassfish.grizzly.Connection.write方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.write方法的具体用法?Java Connection.write怎么用?Java Connection.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.Connection
的用法示例。
在下文中一共展示了Connection.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRequest
import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@Override
public Response sendRequest(Request request, Connection connection) {
AsynReq asynReq = new AsynReq( request);
try {
AsynReq tmp = map.putIfAbsent(request.getHeader().getVersion(), asynReq);
if ( tmp != null )
throw new ConnectionException(request.getHeader().toString() +" was submitted twice");
connection.write( request);
boolean flag = false;
asynReq.getLock().lock();
try {
// set enter flag to true, for notify message received thread
asynReq.setEntered(true);
flag = asynReq.getReady().await( timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
//map.remove( request.getHeader().getVersion() );
//swallow exception
return new Response("InterruptedException", true);
} finally {
asynReq.getLock().unlock();
}
if ( flag == false ) {
logger.error("map size "+map.size()+" "+dumpMap());
throw new StoreException("time out ms "+timeout);
}
else
return asynReq.getResponse() ;
} finally {
if ( asynReq != null ) {
map.remove( asynReq.getRequest().getHeader().getVersion() );
}
}
//return null; //To change body of implemented methods use File | Settings | File Templates.
}
示例2: sendErrorResponse
import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private void sendErrorResponse(final Connection connection, final RequestWrapper request) throws IOException {
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"));
connection.write(responseWrapper, new EmptyCompletionHandler<WriteResult>() {
@Override
public void failed(Throwable throwable) {
LOGGER.error("server write response error,request id is: " + request.getId());
}
});
}
示例3: redirectToPeer
import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
/**
* Redirect data from {@link Connection} to its peer.
*
* @param context
* {@link FilterChainContext}
* @param peerConnection
* peer {@link Connection}
* @throws IOException
*/
@SuppressWarnings("unchecked")
private static void redirectToPeer(final FilterChainContext context,
final Connection peerConnection, Object message) throws IOException {
final Connection srcConnection = context.getConnection();
logger.log(
Level.FINE,
"Redirecting from {0} to {1} message: {2}",
new Object[] { srcConnection.getPeerAddress(),
peerConnection.getPeerAddress(), message });
peerConnection.write(message);
}
示例4: sendMessage
import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@Override
public void sendMessage(Request request, Connection connection) {
connection.write( request);
}
示例5: writeMessage
import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
protected void writeMessage(WSMessage msg) {
IWSCodec codec = getCodec();
byte[] encode = codec.encode(msg);
Connection<?> conn = ensureConnIsOpen();
conn.write(Buffers.wrap(conn.getMemoryManager(), encode));
}