本文整理匯總了Java中org.jboss.netty.channel.Channel類的典型用法代碼示例。如果您正苦於以下問題:Java Channel類的具體用法?Java Channel怎麽用?Java Channel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Channel類屬於org.jboss.netty.channel包,在下文中一共展示了Channel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testAdjOk
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
/**
* Tests adjOk() method.
*/
@Test
public void testAdjOk() throws Exception {
channel = EasyMock.createMock(Channel.class);
ospfInterface.setInterfaceType(OspfInterfaceType.BROADCAST.value());
ospfInterface.setIpAddress(Ip4Address.valueOf("2.2.2.2"));
ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
Ip4Address.valueOf("2.2.2.2"), 2,
topologyForDeviceAndLink);
ospfNbr1.setState(OspfNeighborState.TWOWAY);
ospfNbr1.setNeighborDr(Ip4Address.valueOf("2.2.2.2"));
ospfNbr1.adjOk(channel);
assertThat(ospfNbr1, is(notNullValue()));
ospfInterface.setInterfaceType(OspfInterfaceType.POINT_TO_POINT.value());
ospfNbr1 = new OspfNbrImpl(ospfArea, ospfInterface, Ip4Address.valueOf("1.1.1.1"),
Ip4Address.valueOf("2.2.2.2"), 2,
topologyForDeviceAndLink);
channel = null;
channel = EasyMock.createMock(Channel.class);
ospfNbr1.adjOk(channel);
assertThat(ospfNbr1, is(notNullValue()));
}
示例2: decode
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
if (!channel.isConnected()) {
// In testing, I see decode being called AFTER decode last.
// This check avoids that from reading corrupted frames
return null;
}
// Note that a single call to decode results in reading a single
// OFMessage from the channel buffer, which is passed on to, and processed
// by, the controller (in OFChannelHandler).
// This is different from earlier behavior (with the original openflowj),
// where we parsed all the messages in the buffer, before passing on
// a list of the parsed messages to the controller.
// The performance *may or may not* not be as good as before.
OFMessageReader<OFMessage> reader = OFFactories.getGenericReader();
OFMessage message = reader.readFrom(buffer);
return message;
}
示例3: handleSyncMessage
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
/**
* Handle a generic {@link SyncMessage} and dispatch to an appropriate
* handler
* @param bsm the message
* @param channel the channel on which the message arrived
*/
protected void handleSyncMessage(SyncMessage bsm, Channel channel) {
switch (channelState) {
case OPEN:
case CONNECTED:
switch (bsm.getType()) {
case HELLO:
handshake(bsm.getHello(), channel);
break;
case ECHO_REQUEST:
handleEchoRequest(bsm.getEchoRequest(), channel);
break;
case ERROR:
handleError(bsm.getError(), channel);
break;
default:
// ignore
}
break;
case AUTHENTICATED:
handleSMAuthenticated(bsm, channel);
break;
}
}
示例4: decode
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() >= MESSAGE_HEADER) {
int length = Integer.parseInt(buf.toString(2, 2, StandardCharsets.US_ASCII)) + 5;
if (buf.readableBytes() >= length) {
ChannelBuffer frame = buf.readBytes(length);
while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != '$') {
buf.readByte();
}
return frame;
}
}
return null;
}
示例5: testCommit
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Test(timeout = 60000)
public void testCommit() throws Exception {
HdfsFileStatus status = nn.getRpcServer().getFileInfo("/tmp/bar");
long dirId = status.getFileId();
FileHandle handle = new FileHandle(dirId);
XDR xdr_req = new XDR();
COMMIT3Request req = new COMMIT3Request(handle, 0, 5);
req.serialize(xdr_req);
Channel ch = Mockito.mock(Channel.class);
// Attempt by an unpriviledged user should fail.
COMMIT3Response response1 = nfsd.commit(xdr_req.asReadOnlyWrap(),
ch, 1, securityHandlerUnpriviledged,
new InetSocketAddress("localhost", 1234));
assertEquals("Incorrect return code:", Nfs3Status.NFS3ERR_ACCES,
response1.getStatus());
// Attempt by a priviledged user should pass.
COMMIT3Response response2 = nfsd.commit(xdr_req.asReadOnlyWrap(),
ch, 1, securityHandler,
new InetSocketAddress("localhost", 1234));
assertEquals("Incorrect COMMIT3Response:", null, response2);
}
示例6: checkRepeatedWriteRequest
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
private WriteCtx checkRepeatedWriteRequest(WRITE3Request request,
Channel channel, int xid) {
OffsetRange range = new OffsetRange(request.getOffset(),
request.getOffset() + request.getCount());
WriteCtx writeCtx = pendingWrites.get(range);
if (writeCtx== null) {
return null;
} else {
if (xid != writeCtx.getXid()) {
LOG.warn("Got a repeated request, same range, with a different xid: "
+ xid + " xid in old request: " + writeCtx.getXid());
//TODO: better handling.
}
return writeCtx;
}
}
示例7: decode
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
// Check minimum length
if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
return null;
}
// Check for sync packet
if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
ChannelBuffer syncMessage = buf.readBytes(8);
if (channel != null) {
channel.write(syncMessage);
}
}
return super.decode(ctx, channel, buf);
}
示例8: sendPhotoRequest
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
private void sendPhotoRequest(Channel channel, int pictureId) {
if (channel != null) {
ChannelBuffer photo = photos.get(pictureId);
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
response.writeShort(0x7878); // header
response.writeByte(15); // size
response.writeByte(MSG_X1_PHOTO_DATA);
response.writeInt(pictureId);
response.writeInt(photo.writerIndex());
response.writeShort(Math.min(photo.writableBytes(), 1024));
response.writeShort(++serverIndex);
response.writeShort(Checksum.crc16(Checksum.CRC16_X25,
response.toByteBuffer(2, response.writerIndex() - 2)));
response.writeByte('\r'); response.writeByte('\n'); // ending
channel.write(response);
}
}
示例9: handleRegisterRequest
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
protected void handleRegisterRequest(RegisterRequestMessage request,
Channel channel) {
try {
Scope scope = TProtocolUtil.getScope(request.store.getScope());
if (request.store.isPersist())
syncManager.registerPersistentStore(request.store.storeName,
scope);
else
syncManager.registerStore(request.store.storeName, scope);
RegisterResponseMessage m = new RegisterResponseMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
m.setHeader(header);
SyncMessage bsm =
new SyncMessage(MessageType.REGISTER_RESPONSE);
bsm.setRegisterResponse(m);
channel.write(bsm);
} catch (Exception e) {
channel.write(getError(request.getHeader().getTransactionId(), e,
MessageType.REGISTER_REQUEST));
}
}
示例10: encode
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object message) throws Exception {
if (message instanceof SyncMessage) {
ChannelBuffer buf = new DynamicChannelBuffer(512);
ChannelBufferOutputStream os = new ChannelBufferOutputStream(buf);
TCompactProtocol thriftProtocol =
new TCompactProtocol(new TIOStreamTransport(os));
((SyncMessage) message).write(thriftProtocol);
ChannelBuffer len = ChannelBuffers.buffer(4);
len.writeInt(buf.readableBytes());
return ChannelBuffers.wrappedBuffer(len, buf);
}
return message;
}
示例11: exchangeDone
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
/**
* At this point, the router has sent and received an entire sequence of DD packets.
* Now it must be determined whether the new state is FULL, or LS Request packets
* have to be send.
*
* @param message OSPF message instance
* @param ch netty channel handler
*/
public void exchangeDone(OspfMessage message, Channel ch) {
log.debug("OSPFNbr::exchangeDone...!!!");
stopRxMtDdTimer();
OspfPacketHeader header = (OspfPacketHeader) message;
if (state == OspfNeighborState.EXCHANGE) {
if (lsReqList.isEmpty()) {
state = OspfNeighborState.FULL;
//handler.addDeviceInformation(this);
//handler.addLinkInformation(this, topLevelTlvs);
} else {
state = OspfNeighborState.LOADING;
LsRequest lsRequest = buildLsRequest();
//Setting the destination address
lsRequest.setDestinationIp(header.sourceIp());
byte[] messageToWrite = getMessage(lsRequest);
ch.write(messageToWrite);
setLastSentLsrPacket(lsRequest);
startRxMtLsrTimer(ch);
}
}
}
示例12: parseCommandResponse
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
private Position parseCommandResponse(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position();
position.setProtocol(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
int responseTextLength = buf.bytesBefore((byte) 0);
if (responseTextLength < 0) {
responseTextLength = CMD_RESPONSE_SIZE - 3;
}
position.set(Position.KEY_RESULT, buf.readBytes(responseTextLength).toString(StandardCharsets.UTF_8));
return position;
}
示例13: hasChannel
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
public boolean hasChannel(Channel channel) {
for (Channel channel1 : allChannels) {
if (channel.equals(channel1)) {
return true;
}
}
return false;
}
示例14: testOneWayReceived
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
/**
* Tests oneWayReceived() method.
*/
@Test
public void testOneWayReceived() throws Exception {
ospfMessage = new HelloPacket();
ospfNbr.setState(OspfNeighborState.ATTEMPT);
channel = EasyMock.createMock(Channel.class);
ospfNbr.oneWayReceived(ospfMessage, channel);
channel1 = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.DOWN);
ospfNbr.oneWayReceived(ospfMessage, channel1);
channel2 = EasyMock.createMock(Channel.class);
ospfNbr.setState(OspfNeighborState.TWOWAY);
ospfNbr.oneWayReceived(ospfMessage, channel2);
assertThat(ospfNbr, is(notNullValue()));
}
示例15: execute
import org.jboss.netty.channel.Channel; //導入依賴的package包/類
@Override
public void execute(Channel chan, String[] command) throws DatastoreException
{
m_counter.incrementAndGet();
if (chan.isConnected())
{
Package thisPackage = getClass().getPackage();
String versionString = thisPackage.getImplementationTitle()+" "+thisPackage.getImplementationVersion();
chan.write(versionString+"\n");
}
}