org.jboss.netty.channel.Channel Java Examples

The following examples show how to use org.jboss.netty.channel.Channel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenFileCtx.java    From hadoop with Apache License 2.0 6 votes vote down vote up
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;  
  }
}
 
Example #2
Source File: ShuffleHandler.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  } else if (cause instanceof IOException) {
    if (cause instanceof ClosedChannelException) {
      LOG.debug("Ignoring closed channel error", cause);
      return;
    }
    String message = String.valueOf(cause.getMessage());
    if (IGNORABLE_ERROR_MESSAGE.matcher(message).matches()) {
      LOG.debug("Ignoring client socket close", cause);
      return;
    }
  }

  LOG.error("Shuffle error: ", cause);
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #3
Source File: TestPersistenceProcessorHandler.java    From phoenix-omid with Apache License 2.0 6 votes vote down vote up
@Test(timeOut = 10_000)
public void testProcessingOfBatchPersistEventWith2EventsCommitAndCommitRetry() throws Exception {

    // Prepare test batch
    Batch batch = new Batch(BATCH_ID, BATCH_SIZE);
    batch.addCommit(FIRST_ST, FIRST_CT, null, mock(MonitoringContextImpl.class), Optional.<Long>absent());
    batch.addCommitRetry(SECOND_ST, null, mock(MonitoringContextImpl.class));
    PersistBatchEvent batchEvent = new PersistBatchEvent();
    PersistBatchEvent.makePersistBatch(batchEvent, BATCH_SEQUENCE, batch);

    // Initial assertion
    assertEquals(batch.getNumEvents(), 2);

    // Call process method
    persistenceHandler.onEvent(batchEvent);

    verify(persistenceHandler, times(1)).flush(eq(1));
    verify(persistenceHandler, times(1)).filterAndDissambiguateClientRetries(eq(batch));
    verify(retryProcessor, times(1)).disambiguateRetryRequestHeuristically(eq(SECOND_ST), any(Channel.class), any(MonitoringContextImpl.class));
    verify(replyProcessor, times(1)).manageResponsesBatch(eq(BATCH_SEQUENCE), eq(batch));
    assertEquals(batch.getNumEvents(), 1);
    assertEquals(batch.get(0).getStartTimestamp(), FIRST_ST);
    assertEquals(batch.get(0).getCommitTimestamp(), FIRST_CT);

}
 
Example #4
Source File: MessageEncoder.java    From jstorm with Apache License 2.0 6 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object obj) throws Exception {
    if (obj instanceof MessageBatch) {
        return ((MessageBatch) obj).buffer();
    }

    if (obj instanceof ControlMessage) {
        return ((ControlMessage) obj).buffer();
    }

    if (obj instanceof TaskMessage) {
        return ((TaskMessage) obj).buffer();
    }
    
    throw new RuntimeException("Unsupported encoding of object of class " + obj.getClass().getName());
}
 
Example #5
Source File: MyServerHandler.java    From whiteboard with Apache License 2.0 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
		throws Exception {
	Channel channel = e.getChannel();
	SerializablePath newPath = (SerializablePath) e.getMessage();
	Commons.myUUID = newPath.getMyUUID();

	recordMyUUID(Commons.myUUID, channel);
	System.out.println("������յ���Ϣ,�豸��ʾ��--" + Commons.myUUID);
	if ("send_uuid".equals(newPath.getOPType()))
		return;

	if ("clear".equals(newPath.getOPType())) {
		if (MetadataRepositories.getInstance().getBufferShapes().size() != 0) {
			System.out.println("������������ͼ������");
			MetadataRepositories.getInstance().getBufferShapes().clear();
		}
		return;
	}

	MetadataRepositories.getInstance().getBufferShapes().add(newPath);
	// // ��DZ��͑���д����ͼ������
	sendNewShapeToClient(newPath);
}
 
Example #6
Source File: ThriftFrameEncoder.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #7
Source File: ShuffleHandler.java    From RDFS with Apache License 2.0 6 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
    throws Exception {
  Channel ch = e.getChannel();
  Throwable cause = e.getCause();
  if (cause instanceof TooLongFrameException) {
    sendError(ctx, BAD_REQUEST);
    return;
  }

  LOG.error("Shuffle error: ", cause);
  shuffleMetrics.failedOutput();
  if (ch.isConnected()) {
    LOG.error("Shuffle error " + e);
    sendError(ctx, INTERNAL_SERVER_ERROR);
  }
}
 
Example #8
Source File: RemoteSyncChannelHandler.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Override
protected void handleError(ErrorMessage error, Channel channel) {            
    ErrorType errType = ErrorType.GENERIC;
    for (ErrorType e : ErrorType.values()) {
        if (e.getValue() == error.getError().getErrorCode()) {
            errType = e;
            break;
        }
    }
    SyncException ex = 
            SyncException.newInstance(errType, 
                                      error.getError().getMessage(), 
                                      null);
    if (ChannelState.CONNECTED.equals(channelState) ||
        ChannelState.OPEN.equals(channelState) ||
        ErrorType.AUTH.equals(errType)) {
        syncManager.channelDisconnected(ex);
        channel.close();
    } else {
        SyncReply reply = new SyncReply(null, null, false, ex, 0);
        syncManager.dispatchReply(error.getHeader().getTransactionId(), 
                                  reply);
    }
}
 
Example #9
Source File: RPCChannelHandler.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@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));
    }
}
 
Example #10
Source File: OspfNbrImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Sends the LSA to destination address.
 *
 * @param lsa         LSA instance to sent
 * @param destination destination IP address
 * @param ch          netty channel instance
 */
public void sendLsa(LsaHeader lsa, Ip4Address destination, Channel ch) {
    if (lsa == null) {
        return;
    }

    LsUpdate responseLsUpdate = new LsUpdate();
    // seting OSPF Header
    responseLsUpdate.setOspfVer(OspfUtil.OSPF_VERSION);
    responseLsUpdate.setOspftype(OspfPacketType.LSUPDATE.value());
    responseLsUpdate.setRouterId(ospfArea.routerId());
    responseLsUpdate.setAreaId(ospfArea.areaId());
    responseLsUpdate.setAuthType(OspfUtil.NOT_ASSIGNED);
    responseLsUpdate.setAuthentication(OspfUtil.NOT_ASSIGNED);
    responseLsUpdate.setOspfPacLength(OspfUtil.NOT_ASSIGNED); // to calculate packet length
    responseLsUpdate.setChecksum(OspfUtil.NOT_ASSIGNED);
    responseLsUpdate.setNumberOfLsa(1);
    responseLsUpdate.addLsa(lsa);

    //setting the destination.
    responseLsUpdate.setDestinationIp(destination);
    byte[] messageToWrite = getMessage(responseLsUpdate);
    ch.write(messageToWrite);
}
 
Example #11
Source File: OpenFileCtx.java    From big-c with Apache License 2.0 6 votes vote down vote up
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;  
  }
}
 
Example #12
Source File: NettyAsyncHttpProvider.java    From ck with Apache License 2.0 6 votes vote down vote up
private Channel lookupInCache(URI uri) {
	Channel channel = connectionsPool.remove(getBaseUrl(uri));
	if (channel != null) {
		/**
		 * The Channel will eventually be closed by Netty and will becomes invalid.
		 * We might suffer a memory leak if we don't scan for closed channel. The
		 * AsyncHttpClientConfig.reaper() will always make sure those are cleared.
		 */
		if (channel.isOpen()) {
			channel.setReadable(true);
		} else {
			return null;
		}
	}
	return channel;
}
 
Example #13
Source File: ProgrammableTSOServer.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private void sendAbortResponse(long startTimestamp, Channel c) {
    TSOProto.Response.Builder builder = TSOProto.Response.newBuilder();
    TSOProto.CommitResponse.Builder commitBuilder = TSOProto.CommitResponse.newBuilder();
    commitBuilder.setAborted(true).setStartTimestamp(startTimestamp);
    builder.setCommitResponse(commitBuilder.build());
    c.write(builder.build());
}
 
Example #14
Source File: AddressFilterAdaptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(Channel channel) {
    final InetSocketAddress remoteAddress = (InetSocketAddress) channel.getRemoteAddress();
    if (remoteAddress == null) {
        return true;
    }
    InetAddress address = remoteAddress.getAddress();
    return filter.accept(address);
}
 
Example #15
Source File: PcepClientImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public final void setChannel(Channel channel) {
    this.channel = channel;
    final SocketAddress address = channel.getRemoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    }
}
 
Example #16
Source File: NettyTransport.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
protected Channel nodeChannel(DiscoveryNode node, TransportRequestOptions options) throws ConnectTransportException {
    NodeChannels nodeChannels = connectedNodes.get(node);
    if (nodeChannels == null) {
        throw new NodeNotConnectedException(node, "Node not connected");
    }
    return nodeChannels.channel(options.type());
}
 
Example #17
Source File: PacketEncoder.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception {
    if (!(msg instanceof Packet)) {
        logger.error("invalid packet:{} channel:{}", msg, channel);
        return null;
    }
    Packet packet = (Packet) msg;
    return packet.toBuffer();
}
 
Example #18
Source File: NettyCodecAdapter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel ch, Object msg) throws Exception {
    com.alibaba.dubbo.remoting.buffer.ChannelBuffer buffer =
        com.alibaba.dubbo.remoting.buffer.ChannelBuffers.dynamicBuffer(1024);
    NettyChannel channel = NettyChannel.getOrAddChannel(ch, url, handler);
    try {
    	codec.encode(channel, buffer, msg);
    } finally {
        NettyChannel.removeChannelIfDisconnected(ch);
    }
    return ChannelBuffers.wrappedBuffer(buffer.toByteBuffer());
}
 
Example #19
Source File: DefaultIsisInterfaceTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    channel = EasyMock.createNiceMock(Channel.class);
    defaultIsisInterface = new DefaultIsisInterface();
    defaultIsisInterface.setInterfaceMacAddress(macAddress);
    isisHeader = new IsisHeader();
    isisHeader.setIrpDiscriminator((byte) 1);
    helloPdu = new L1L2HelloPdu(isisHeader);
    isisInterface = new DefaultIsisInterface();
    defaultIsisNeighbor = new DefaultIsisNeighbor(helloPdu, isisInterface);
    defaultIsisNeighbor.setNeighborMacAddress(macAddress);
    isisLsdb = new DefaultIsisLsdb();
}
 
Example #20
Source File: MemcachedCommandHandler.java    From fqueue with Apache License 2.0 5 votes vote down vote up
protected void handleAdd(ChannelHandlerContext channelHandlerContext, CommandMessage<CACHE_ELEMENT> command,
		Channel channel) throws DatabaseException, Exception {
	Cache.StoreResponse ret;
	ret = cache.add(command.element);
	Channels.fireMessageReceived(channelHandlerContext, new ResponseMessage(command).withResponse(ret), channel
			.getRemoteAddress());
}
 
Example #21
Source File: DefaultPinpointClientHandler.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public SocketAddress getRemoteAddress() {
    final Channel channel = this.channel;
    if (channel == null) {
        return null;
    }
    return channel.getRemoteAddress();
}
 
Example #22
Source File: AbstractRequestProcessor.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private void handleFence(RequestEvent event) throws Exception {
    long tableID = event.getTableId();
    Channel c = event.getChannel();

    long fenceTimestamp = timestampOracle.next();

    tableFences.put(tableID, fenceTimestamp);

    event.monCtx.timerStart("reply.processor.fence.latency");
    replyProcessor.sendFenceResponse(tableID, fenceTimestamp, c, event.monCtx);
}
 
Example #23
Source File: HealthCheckManagerTest.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Test
public void pingPacketTest() throws Exception {
    ChannelGroup channelGroup = new DefaultChannelGroup();

    HealthCheckManager healthCheckManager = new HealthCheckManager(timer, 3000, channelGroup);
    healthCheckManager.start(1000);

    Channel mockChannel = createMockChannel(HealthCheckState.RECEIVED);
    channelGroup.add(mockChannel);
    try {
        verify(mockChannel, timeout(3000).atLeastOnce()).write(PingSimplePacket.PING_PACKET);
    } finally {
        healthCheckManager.stop();
    }
}
 
Example #24
Source File: MyServerHandler.java    From whiteboard with Apache License 2.0 5 votes vote down vote up
/**
 * ��¼��ǰ�豸Ψһ��ʾ����Channel�໥��Ӧ
 */
private void recordMyUUID(String myUUID, Channel channel) {

	if (MetadataRepositories.getInstance().getChannels()
			.containsKey(myUUID)
			&& MetadataRepositories.getInstance().getChannels().get(myUUID)
					.isOpen())
		return;

	MetadataRepositories.getInstance().getChannels().put(myUUID, channel);
}
 
Example #25
Source File: FpmFrameDecoder.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
        throws Exception {

    if (!channel.isConnected()) {
        return null;
    }

    if (buffer.readableBytes() < FpmHeader.FPM_HEADER_LENGTH) {
        return null;
    }

    buffer.markReaderIndex();

    short version = buffer.readUnsignedByte();
    short type = buffer.readUnsignedByte();
    int length = buffer.readUnsignedShort();

    buffer.resetReaderIndex();

    if (buffer.readableBytes() < length) {
        // Not enough bytes to read a whole message
        return null;
    }

    byte[] fpmMessage = new byte[length];
    buffer.readBytes(fpmMessage);

    return FpmHeader.decode(fpmMessage, 0, fpmMessage.length);
}
 
Example #26
Source File: TestPersistenceProcessorHandler.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Test(timeOut = 10_000)
public void testProcessingOfBatchPersistEventWithMultipleRetryAndNonRetryEvents() throws Exception {

    // Prepare test batch
    Batch batch = new Batch(BATCH_ID, BATCH_SIZE);

    batch.addTimestamp(FIRST_ST, null, mock(MonitoringContextImpl.class));
    batch.addCommitRetry(SECOND_ST, null, mock(MonitoringContextImpl.class));
    batch.addCommit(THIRD_ST, THIRD_CT, null, mock(MonitoringContextImpl.class), Optional.<Long>absent());
    batch.addAbort(FOURTH_ST, null, mock(MonitoringContextImpl.class));
    batch.addCommit(FIFTH_ST, FIFTH_CT, null, mock(MonitoringContextImpl.class), Optional.<Long>absent());
    batch.addCommitRetry(SIXTH_ST, null, mock(MonitoringContextImpl.class));
    PersistBatchEvent batchEvent = new PersistBatchEvent();
    PersistBatchEvent.makePersistBatch(batchEvent, BATCH_SEQUENCE, batch);

    // Initial assertion
    assertEquals(batch.getNumEvents(), 6);

    // Call process method
    persistenceHandler.onEvent(batchEvent);

    verify(persistenceHandler, times(1)).flush(2); // 2 commits to flush
    verify(persistenceHandler, times(1)).filterAndDissambiguateClientRetries(eq(batch));
    verify(retryProcessor, times(1)).disambiguateRetryRequestHeuristically(eq(SECOND_ST), any(Channel.class), any(MonitoringContextImpl.class));
    verify(replyProcessor, times(1)).manageResponsesBatch(eq(BATCH_SEQUENCE), eq(batch));
    assertEquals(batch.getNumEvents(), 4);
    assertEquals(batch.get(0).getStartTimestamp(), FIRST_ST);
    assertEquals(batch.get(1).getStartTimestamp(), FIFTH_ST);
    assertEquals(batch.get(1).getCommitTimestamp(), FIFTH_CT);
    assertEquals(batch.get(2).getStartTimestamp(), THIRD_ST);
    assertEquals(batch.get(2).getCommitTimestamp(), THIRD_CT);
    assertEquals(batch.get(3).getStartTimestamp(), FOURTH_ST);

}
 
Example #27
Source File: AddressFilterAdaptorTest.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Test
public void accept_reject() {
    String ignoreString = "10.0.0.1";
    AddressFilter ignoreAddressFilter = new IgnoreAddressFilter(Collections.singletonList(ignoreString));

    Channel ignoreChannel = mockChannel(ignore);
    AddressFilterAdaptor adaptor = new AddressFilterAdaptor(ignoreAddressFilter);

    Assert.assertFalse(adaptor.accept(ignoreChannel));
}
 
Example #28
Source File: TestTSOChannelHandlerNetty.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private void testWritingFenceRequest(Channel channel) throws InterruptedException {
    // Reset mock
    reset(requestProcessor);
    TSOProto.Request.Builder fenceBuilder = TSOProto.Request.newBuilder();
    TSOProto.FenceRequest.Builder fenceRequestBuilder = TSOProto.FenceRequest.newBuilder();
    fenceRequestBuilder.setTableId(666);
    fenceBuilder.setFenceRequest(fenceRequestBuilder.build());
    TSOProto.Request r = fenceBuilder.build();
    assertTrue(r.hasFenceRequest());
    // Write into the channel
    channel.write(fenceBuilder.build()).await();
    verify(requestProcessor, timeout(100).never()).timestampRequest(any(Channel.class), any(MonitoringContextImpl.class));
    verify(requestProcessor, timeout(100).times(1))
            .fenceRequest(eq(666L), any(Channel.class), any(MonitoringContextImpl.class));
}
 
Example #29
Source File: TestReplyProcessor.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateLowWaterMarkOnlyForMaxInBatch() throws Exception {

    Batch thirdBatch = batchPool.borrowObject();
    thirdBatch.addTimestamp(FIRST_ST, mock(Channel.class), monCtx);
    thirdBatch.addCommit(SECOND_ST, SECOND_CT, mock(Channel.class), monCtx, Optional.of(100L));
    thirdBatch.addCommit(THIRD_ST, THIRD_CT, mock(Channel.class), monCtx, Optional.of(50L));
    thirdBatch.addCommit(FOURTH_ST, FOURTH_CT, mock(Channel.class), monCtx, Optional.<Long>absent());
    thirdBatch.addCommit(FIFTH_ST, FIFTH_CT, mock(Channel.class), monCtx, Optional.of(100L));
    thirdBatch.addCommit(SIXTH_ST, SIXTH_CT, mock(Channel.class), monCtx, Optional.of(150L));

    ReplyBatchEvent thirdBatchEvent = ReplyBatchEvent.EVENT_FACTORY.newInstance();
    ReplyBatchEvent.makeReplyBatch(thirdBatchEvent, thirdBatch, 0);

    replyProcessor.onEvent(thirdBatchEvent, ANY_DISRUPTOR_SEQUENCE, false);

    InOrder inOrderWatermarkWriter = inOrder(lowWatermarkWriter, lowWatermarkWriter, lowWatermarkWriter);

    inOrderWatermarkWriter.verify(lowWatermarkWriter, times(1)).persistLowWatermark(eq(100L));
    inOrderWatermarkWriter.verify(lowWatermarkWriter, times(1)).persistLowWatermark(eq(150L));

    verify(lowWatermarkWriter, timeout(100).never()).persistLowWatermark(eq(50L));

    InOrder inOrderCheckLWM = inOrder(replyProcessor, replyProcessor,replyProcessor,replyProcessor,replyProcessor);
    inOrderCheckLWM.verify(replyProcessor, times(1)).updateLowWatermark(Optional.of(100L));
    inOrderCheckLWM.verify(replyProcessor, times(1)).updateLowWatermark(Optional.of(50L));
    inOrderCheckLWM.verify(replyProcessor, times(1)).updateLowWatermark(Optional.<Long>absent());
    inOrderCheckLWM.verify(replyProcessor, times(1)).updateLowWatermark(Optional.of(100L));
    inOrderCheckLWM.verify(replyProcessor, times(1)).updateLowWatermark(Optional.of(150L));

}
 
Example #30
Source File: FileClient.java    From netty-file-parent with Apache License 2.0 5 votes vote down vote up
private static void replaceFile(ClientBootstrap bootstrap, String host,
		int port, File file, String filePath, String userName, String pwd) {
	URI uri = getUri(host, port);
	ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
			port));
	Channel channel = future.awaitUninterruptibly().getChannel();
	if (!future.isSuccess()) {
		future.getCause().printStackTrace();
		bootstrap.releaseExternalResources();
		return;
	}

	WrapFileClientHandler handler = new ReplaceFileClientHandler(host, uri,
			filePath, file, userName, pwd);
	HttpRequest request = handler.getRequest();
	HttpDataFactory factory = getHttpDataFactory();
	HttpPostRequestEncoder bodyRequestEncoder = handler
			.wrapRequestData(factory);
	channel.write(request);
	if (bodyRequestEncoder.isChunked()) {
		channel.write(bodyRequestEncoder).awaitUninterruptibly();
	}
	bodyRequestEncoder.cleanFiles();
	channel.getCloseFuture().awaitUninterruptibly();
	bootstrap.releaseExternalResources();
	factory.cleanAllHttpDatas();
}