本文整理匯總了Java中org.apache.mina.filter.codec.ProtocolEncoderOutput.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java ProtocolEncoderOutput.flush方法的具體用法?Java ProtocolEncoderOutput.flush怎麽用?Java ProtocolEncoderOutput.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.mina.filter.codec.ProtocolEncoderOutput
的用法示例。
在下文中一共展示了ProtocolEncoderOutput.flush方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSendBuffer
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
/**
* 同步處理要發送的數據。
*
* @param bytes
* @return
*/
public void getSendBuffer(byte[] bytes, ProtocolEncoderOutput out,
MapleClient client) {
IoBuffer buffer = IoBuffer.allocate(bytes.length + 4, true);
try {
mutex.lock();
buffer.put(getPacketHeader(bytes.length));
buffer.put(bytes);
buffer.position(buffer.position() - bytes.length);
crypt(buffer, true);
buffer.flip();
// 建立完成待發送數據。
out.write(buffer);
out.flush();
} finally {
mutex.unlock();
}
buffer.free();
}
示例2: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
@Override
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception {
try {
byte compressedBytes[] = (byte[]) message;
final IoBuffer buffer = IoBuffer.allocate(compressedBytes.length).setAutoExpand(true);
buffer.put(compressedBytes);
buffer.flip();
out.write(buffer);
WriteFuture wf = out.flush();
wf.addListener(new IoFutureListener<IoFuture>() {
@Override
public void operationComplete(IoFuture future) {
buffer.free();
}
});
out.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
/** {@inheritDoc} */
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws ProtocolCodecException {
final ProtocolState state = (ProtocolState) session.getAttribute(ProtocolState.SESSION_KEY);
// pass the connection to the encoder for its use
encoder.setConnection((RTMPConnection) session.getAttribute(RTMPConnection.RTMP_CONNECTION_KEY));
try {
// We need to synchronize on the output and flush the generated data to prevent two packages to the same channel
// to be sent in different order thus resulting in wrong headers being generated.
final IoBuffer buf = encoder.encode(state, message);
if (buf != null) {
out.write(buf);
out.mergeAll();
out.flush();
} else {
log.trace("Response buffer was null after encoding");
}
} catch (Exception ex) {
log.error("Exception during encode", ex);
}
}
示例4: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) throws Exception {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
codec.encode(channel, buffer, msg);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
out.write(ByteBuffer.wrap(buffer.toByteBuffer()));
out.flush();
}
示例5: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
@Override
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
byte[] encodedMessage;
try {
encodedMessage = encoder.encode(message);
} catch (Throwable e) {
log.error("Message encoder error", e);
throw e;
}
if (encodedMessage != null && encodedMessage.length > 0) {
IoBuffer buffer = IoBuffer.wrap(encodedMessage);
out.write(buffer);
out.flush();
}
}
示例6: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
public void encode(IoSession session, Object msg, ProtocolEncoderOutput out) throws Exception {
ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
MinaChannel channel = MinaChannel.getOrAddChannel(session, url, handler);
try {
codec.encode(channel, buffer, msg);
} finally {
MinaChannel.removeChannelIfDisconnectd(session);
}
out.write(ByteBuffer.wrap(buffer.toByteBuffer()));
out.flush();
}
示例7: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
final ByteBuffer buffer;
if (message instanceof ProtocolMessage) {
ProtocolMessage pm = (ProtocolMessage) message;
nioLogger.log(PROTOCOL, session, "CougarProtocolEncoder: Writing protocol message %s", pm.getProtocolMessageType());
Byte version = (Byte) session.getAttribute(CougarProtocol.PROTOCOL_VERSION_ATTR_NAME);
// go for lowest likely common denominator, since this will likely only occur for RejectMessages
if (version == null) {
version = CougarProtocol.TRANSPORT_PROTOCOL_VERSION_MIN_SUPPORTED;
}
buffer = pm.getSerialisedForm(version);
if (buffer == null) {
badMessagesRequested.incrementAndGet();
throw new IllegalArgumentException("Couldn't serialise ProtocolMessage [" + ((ProtocolMessage) message).getProtocolMessageType() + "]");
}
switch (pm.getProtocolMessageType()) {
case ACCEPT:
acceptsSent.incrementAndGet();
break;
case CONNECT:
connectsSent.incrementAndGet();
break;
case REJECT:
rejectsSent.incrementAndGet();
break;
case KEEP_ALIVE:
keepAlivesSent.incrementAndGet();
break;
case DISCONNECT:
disconnectsSent.incrementAndGet();
break;
case MESSAGE_REQUEST:
messageRequestsSent.incrementAndGet();
nioLogger.log(ALL, session, "CougarProtocolEncoder: Writing message of length %s", (((RequestMessage) pm).getPayload().length + 8));
break;
case MESSAGE_RESPONSE:
messageRequestsSent.incrementAndGet();
nioLogger.log(ALL, session, "CougarProtocolEncoder: Writing message of length %s", ((ResponseMessage) pm).getPayload().length);
break;
case EVENT:
eventsSent.incrementAndGet();
nioLogger.log(ALL, session, "CougarProtocolEncoder: Writing event of length %s", ((EventMessage) pm).getPayload().length);
break;
case SUSPEND:
suspendsSent.incrementAndGet();
break;
case START_TLS_REQUEST:
tlsRequestsSent.incrementAndGet();
break;
case START_TLS_RESPONSE:
tlsResponsesSent.incrementAndGet();
break;
default:
badMessagesRequested.incrementAndGet();
throw new IllegalArgumentException("Unknown ProtocolMessage [" + ((ProtocolMessage) message).getProtocolMessageType() + "] received");
}
} else {
throw new IllegalArgumentException("Unknown message type " + message);
}
buffer.flip();
out.write(buffer);
out.flush();
}
示例8: encode
import org.apache.mina.filter.codec.ProtocolEncoderOutput; //導入方法依賴的package包/類
@Override
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception {
byte[] bytes = (byte[])message;
IoBuffer buffer = IoBuffer.allocate(256);
buffer.setAutoExpand(true);
buffer.put(bytes);
buffer.flip();
out.write(buffer);
out.flush();
buffer.free();
}