Java Code Examples for org.jboss.netty.channel.Channel#isWritable()

The following examples show how to use org.jboss.netty.channel.Channel#isWritable() . 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: NettyClientAsync.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public Channel waitForChannelReady() {
    Channel channel = channelRef.get();
    long pendingTime = 0;
    while ((channel == null && !isClosed()) || (channel != null && !channel.isWritable())) {
        JStormUtils.sleepMs(1);
        pendingTime++;
        if (discardCheck(pendingTime, timeoutMs, messageBuffer.size())) {
            messageBuffer.clear();
            return null;
        }
        if (pendingTime % 30000 == 0) {
            LOG.info("Pending total time={}, channel.isWritable={}, pendingNum={}, remoteAddress={}", pendingTime, channel != null ? channel.isWritable()
                    : null, pendings.get(), channel != null ? channel.getRemoteAddress() : null);
        }
        channel = channelRef.get();
    }
    return channel;
}
 
Example 2
Source File: RaopAudioHandler.java    From Android-Airplay-Server with MIT License 5 votes vote down vote up
@Override
public void writeRequested(final ChannelHandlerContext ctx, final MessageEvent evt) throws Exception {
	final RaopRtpPacket packet = (RaopRtpPacket)evt.getMessage();

	/* Get control and timing channel from the enclosing RaopAudioHandler */
	Channel tempControlChannel = null;
	Channel tempTimingChannel = null;
	
	synchronized(RaopAudioHandler.this) {
		tempControlChannel = controlChannel;
		tempTimingChannel = timingChannel;
	}

	if (packet instanceof RaopRtpPacket.RetransmitRequest) {
		if ((tempControlChannel != null) && tempControlChannel.isOpen() && tempControlChannel.isWritable()){
			tempControlChannel.write(evt.getMessage());
		}
	}
	else if (packet instanceof RaopRtpPacket.TimingRequest) {
		if ((tempTimingChannel != null) && tempTimingChannel.isOpen() && tempTimingChannel.isWritable()){
			tempTimingChannel.write(evt.getMessage());
		}
	}
	else {
		super.writeRequested(ctx, evt);
	}
}
 
Example 3
Source File: NettyClient.java    From jstorm with Apache License 2.0 5 votes vote down vote up
Channel isChannelReady() {
    Channel channel = channelRef.get();
    if (channel == null) {
        return null;
    }

    // improve performance skill check
    if (!channel.isWritable()) {
        return null;
    }

    return channel;
}
 
Example 4
Source File: RaopRtpRetransmitRequestHandler.java    From Android-Airplay-Server with MIT License 4 votes vote down vote up
/**
 * Scan the list of in-flight retransmit requests and send
 * {@link RetransmitRequest} packets if it's past the time
 * at which we expected the packet to arrive
 * 
 * @param channel channel used to send retransmit requests
 * @param nextSecondsTime
 */
private synchronized void requestRetransmits(final Channel channel, final double nextSecondsTime) {
	/* The retransmit request we're currently building */
	RaopRtpPacket.RetransmitRequest retransmitRequest = null;

	/* Run through open retransmit requests */
	final Iterator<MissingPacket> missingPacketIterator = m_missingPackets.iterator();
	while (missingPacketIterator.hasNext()) {
		final MissingPacket missingPacket = missingPacketIterator.next();

		/* If it's past the time at which the packet would have needed to be queued,
		 * warn and forget about it
		 */
		if (missingPacket.requiredUntilSecondsTime <= nextSecondsTime) {
			s_logger.warning("Packet " + missingPacket.sequence + " was required " + (nextSecondsTime - missingPacket.requiredUntilSecondsTime) + " secons ago, giving up");

			missingPacketIterator.remove();
			continue;
		}

		/* If the packet isn't expected until later,
		 * skip it for now */
		if (missingPacket.expectedUntilSecondsTime > nextSecondsTime)
			continue;

		/* Ok, the packet is overdue */
		
		if (missingPacket.retransmitRequestCount >= RetransmitAttempts) {
			/* If the packet was already requests too often,
			 * warn and forget about it */
			s_logger.warning("Packet " + missingPacket.sequence + " overdue " + (nextSecondsTime - missingPacket.expectedUntilSecondsTime) + " seconds after " + missingPacket.retransmitRequestCount + " retransmit requests, giving up");

			missingPacketIterator.remove();
			continue;
		}
		else {
			/* Log that we're about to request retransmission */
			final int retransmitRequestCountPrevious = missingPacket.retransmitRequestCount;
			final double expectedUntilSecondsTimePrevious = missingPacket.expectedUntilSecondsTime;
			missingPacket.sentRetransmitRequest(nextSecondsTime);

			s_logger.fine("Packet " + missingPacket.sequence + " overdue " + (nextSecondsTime - expectedUntilSecondsTimePrevious) + " seconds after " + retransmitRequestCountPrevious + " retransmit requests, requesting again expecting response in " + (missingPacket.expectedUntilSecondsTime - nextSecondsTime) + " seconds");
		}

		/* Ok, really request re-transmission */
		
		if (
			(retransmitRequest != null) &&
			(sequenceAdd(retransmitRequest.getSequenceFirst(), retransmitRequest.getSequenceCount()) != missingPacket.sequence)
		) {
			/* There is a current retransmit request, but the sequence cannot be appended.
			 * We transmit the current request and start building a new one
			 */
			if (channel.isOpen() && channel.isWritable())
				channel.write(retransmitRequest);
			retransmitRequest = null;
		}
		
		/* If there still is a current retransmit request, the sequence can be appended */

		if (retransmitRequest == null) {
			/* Create new retransmit request */
			m_retransmitRequestSequence = sequenceSuccessor(m_retransmitRequestSequence);
			retransmitRequest = new RaopRtpPacket.RetransmitRequest();
			retransmitRequest.setSequence(m_retransmitRequestSequence);
			retransmitRequest.setSequenceFirst(missingPacket.sequence);
			retransmitRequest.setSequenceCount(1);
		}
		else {
			/* Append sequnce to current retransmit request */
			retransmitRequest.setSequenceCount(retransmitRequest.getSequenceCount() + 1);
		}
	}
	if (retransmitRequest != null) {
		/* Send the retransmit request we were building when the loop ended */
		if (channel.isOpen() && channel.isWritable())
			channel.write(retransmitRequest);
	}
}