Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  // This software is released into the Public Domain.  See copying.txt for details.
  package org.openstreetmap.osmosis.replicationhttp.v0_6.impl;
Netty handler for receiving replication sequence information and notifying listeners.

Brett Henderson
 public abstract class SequenceClientHandler extends SimpleChannelHandler {
 	private static final Logger LOG = Logger.getLogger(SequenceClientHandler.class.getName());
 	private String serverHost;
 	private boolean midStream;
 	private boolean active;

Creates a new instance.

control Provides the Netty handlers with access to the controller.
serverHost The name of the host system running the sequence server.
 	public SequenceClientHandler(SequenceClientControl controlString serverHost) {
 		this. = control;
 		this. = serverHost;
 		 = true;

Gets the URI to request from the server to initialise message processing.

The request URI.
 	protected abstract String getRequestUri();
 		// Send a request to the server asking for sequence number
 		// notifications.
 		Channels.write(ctxe.getFuture(), request);
 		 = false;

Processes the contents of a single HTTP chunk.

buffer The data contained in the chunk.
 	protected abstract void processMessageData(ChannelBuffer buffer);
 	public void messageReceived(ChannelHandlerContext ctxMessageEvent ethrows Exception {
 		if () {
 			ChannelBuffer buffer;
 			if (!) {
 				HttpResponse response = (HttpResponsee.getMessage();
 				HttpResponseStatus status = response.getStatus();
 				if (!..equals(status)) {
 					throw new OsmosisRuntimeException("Received a " + status + " response from the server.");
 				buffer = response.getContent();
 				 = true;
 			} else {
				HttpChunk chunk = (HttpChunke.getMessage();
				buffer = chunk.getContent();
			// Perform implementation specific processing of the buffer contents.
			if (buffer.readableBytes() > 0) {
		// When we close the channel we may still continue to receive some
		// data. Flag that this should be ignored.
		 = false;
		// Get the cause of the exception.
		Throwable t = e.getCause();
		// A ClosedChannelException occurs if the client disconnects and is not
		// an error scenario.
		if (!(t instanceof ClosedChannelException)) {
			.log(."Error during processing for channel " + ctx.getChannel() + "."t);
		// We must stop sending to this client if any errors occur during
		// processing.
New to GrepCode? Check out our FAQ X