~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/wsstack/src/main/java/com/eucalyptus/ws/handlers/ServiceSinkHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 */
64
64
package com.eucalyptus.ws.handlers;
65
65
 
 
66
import java.util.concurrent.atomic.AtomicLong;
 
67
 
66
68
import org.apache.log4j.Logger;
67
69
import org.jboss.netty.channel.ChannelEvent;
68
70
import org.jboss.netty.channel.ChannelFutureListener;
78
80
import org.jboss.netty.handler.codec.http.HttpHeaders;
79
81
import org.jboss.netty.handler.codec.http.HttpResponse;
80
82
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
 
83
import org.jboss.netty.handler.codec.http.HttpVersion;
81
84
import org.jboss.netty.handler.timeout.IdleStateEvent;
82
85
import org.mule.DefaultMuleMessage;
83
86
import org.mule.api.MuleMessage;
103
106
@ChannelPipelineCoverage( "one" )
104
107
public class ServiceSinkHandler extends SimpleChannelHandler {
105
108
  private static Logger                          LOG          = Logger.getLogger( ServiceSinkHandler.class );
106
 
  private long                                   startTime;
 
109
  private AtomicLong  startTime = new AtomicLong(0l);
107
110
  private final ChannelLocal<MappingHttpMessage> requestLocal = new ChannelLocal<MappingHttpMessage>( );
108
111
  
109
112
  private NioMessageReceiver                     msgReceiver;
155
158
 
156
159
  private void sendDownstreamNewEvent( ChannelHandlerContext ctx, ChannelEvent e, EucalyptusMessage reply ) {
157
160
    final MappingHttpMessage request = this.requestLocal.get( ctx.getChannel( ) );
 
161
    if(request != null) {
158
162
    if ( reply == null ) {
159
163
      LOG.warn( "Received a null response for request: " + request.getMessageString( ) );
160
164
      reply = new EucalyptusErrorMessageType( this.getClass( ).getSimpleName( ), ( EucalyptusMessage ) request.getMessage( ), "Received a NULL reply" );
161
165
    }
162
 
    LOG.info( EventRecord.here( Component.eucalyptus, EventType.MSG_SERVICED, reply.getClass( ).getSimpleName( ) ) );
 
166
    LOG.info( EventRecord.here( Component.eucalyptus, EventType.MSG_SERVICED, reply.getClass( ).getSimpleName( ), Long.toString( System.currentTimeMillis( ) - this.startTime.get( ) ) ) );
163
167
    final MappingHttpResponse response = new MappingHttpResponse( request.getProtocolVersion( ) );
164
168
    final DownstreamMessageEvent newEvent = new DownstreamMessageEvent( ctx.getChannel( ), e.getFuture( ), response, null );
165
169
    response.setMessage( reply );
166
170
    ctx.sendDownstream( newEvent );
 
171
    }
167
172
  }
168
173
  
169
174
  @Override
172
177
    if ( e instanceof ExceptionEvent ) {
173
178
      this.exceptionCaught( ctx, ( ExceptionEvent ) e );
174
179
    } else if ( e instanceof MessageEvent ) {
175
 
      this.startTime = System.currentTimeMillis( );
 
180
      this.startTime.compareAndSet( 0l, System.currentTimeMillis( ) );
176
181
      final MessageEvent event = ( MessageEvent ) e;
177
182
      if ( event.getMessage( ) instanceof MappingHttpMessage ) {
178
183
        final MappingHttpMessage request = ( MappingHttpMessage ) event.getMessage( );
192
197
          Messaging.dispatch( "vm://RequestQueue", msg );
193
198
        } else if ( ( user == null ) || ( ( user != null ) && user.getIsAdministrator( ) ) ) {
194
199
          final MuleMessage reply = this.msgReceiver.routeMessage( new DefaultMuleMessage( msg ) );
195
 
          ctx.getChannel( ).write( reply.getPayload( ) );
 
200
          if(reply != null)
 
201
              ctx.getChannel( ).write( reply.getPayload( ) );
196
202
        } else {
197
203
          ctx.getChannel( ).write( new MappingHttpResponse( request.getProtocolVersion( ), HttpResponseStatus.FORBIDDEN ) );
198
204
        }