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


Java Channel类代码示例

本文整理汇总了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()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:OspfNbrImplTest.java

示例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;
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:OFMessageDecoder.java

示例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;
    }
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:30,代码来源:AbstractRPCChannelHandler.java

示例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;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:Gps056FrameDecoder.java

示例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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:TestRpcProgramNfs3.java

示例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;  
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:OpenFileCtx.java

示例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);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:IntellitracFrameDecoder.java

示例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);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:18,代码来源:Gt06ProtocolDecoder.java

示例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));
    }
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:24,代码来源:RPCChannelHandler.java

示例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;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:17,代码来源:ThriftFrameEncoder.java

示例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);
        }
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:33,代码来源:OspfNbrImpl.java

示例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;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:AdmProtocolDecoder.java

示例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;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:NettyTransport.java

示例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()));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:18,代码来源:OspfNbrImplTest.java

示例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");
	}
}
 
开发者ID:quqiangsheng,项目名称:abhot,代码行数:12,代码来源:VersionCommand.java


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