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


Java ProtocolEncoderOutput.flush方法代碼示例

本文整理匯總了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();
}
 
開發者ID:316181444,項目名稱:Hxms,代碼行數:26,代碼來源:MapleAESOFB.java

示例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();
	}
}
 
開發者ID:myking520,項目名稱:gamefm,代碼行數:23,代碼來源:LuaEncoder.java

示例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);
	}
}
 
開發者ID:cwpenhale,項目名稱:red5-mobileconsole,代碼行數:21,代碼來源:RTMPMinaProtocolEncoder.java

示例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();
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:12,代碼來源:MinaCodecAdapter.java

示例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();
	}
}
 
開發者ID:ugcs,項目名稱:ugcs-java-sdk,代碼行數:16,代碼來源:MinaEncoder.java

示例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();
}
 
開發者ID:hufeng,項目名稱:dubbo2.js,代碼行數:12,代碼來源:MinaCodecAdapter.java

示例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();
}
 
開發者ID:betfair,項目名稱:cougar,代碼行數:74,代碼來源:CougarProtocolEncoder.java

示例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();
	
	
}
 
開發者ID:xcjava,項目名稱:ymesb,代碼行數:20,代碼來源:ByteArrayEncoder.java


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