Skip to content

Commit

Permalink
wait on context
Browse files Browse the repository at this point in the history
  • Loading branch information
grze committed Apr 20, 2011
1 parent c9d9cac commit a981897
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Expand Up @@ -14,6 +14,7 @@
import com.eucalyptus.component.ServiceConfiguration;
import com.eucalyptus.component.ServiceConfigurations;
import com.eucalyptus.component.ServiceRegistrationException;
import com.eucalyptus.component.id.ClusterController;
import com.eucalyptus.component.id.Eucalyptus;
import com.eucalyptus.config.ClusterConfiguration;
import com.eucalyptus.config.DeregisterClusterType;
Expand All @@ -28,7 +29,7 @@
import com.eucalyptus.scripting.groovy.GroovyUtil;
import com.eucalyptus.system.SubDirectory;

@DiscoverableServiceBuilder( com.eucalyptus.component.id.ClusterController.class )
@DiscoverableServiceBuilder( ClusterController.class )
@Handles( { RegisterClusterType.class, DeregisterClusterType.class, DescribeClustersType.class, ClusterConfiguration.class, ModifyClusterAttributeType.class } )
public class ClusterBuilder extends DatabaseServiceBuilder<ClusterConfiguration> {
static Logger LOG = Logger.getLogger( ClusterBuilder.class );
Expand Down Expand Up @@ -84,7 +85,7 @@ public ClusterConfiguration newInstance( String partition, String name, String h

@Override
public Component getComponent( ) {
return Components.lookup( com.eucalyptus.component.id.ClusterController.class );
return Components.lookup( ClusterController.class );
}

@Override
Expand Down
Expand Up @@ -20,6 +20,10 @@ public class Contexts {
private static ConcurrentMap<String, Context> uuidContexts = new ConcurrentHashMap<String, Context>( MAX, THRESHOLD, CONCUR );
private static ConcurrentMap<Channel, Context> channelContexts = new ConcurrentHashMap<Channel, Context>( MAX, THRESHOLD, CONCUR );

static boolean hasOutstandingRequests( ) {
return uuidContexts.keySet( ).size( ) > 0;
}

public static Context create( MappingHttpRequest request, Channel channel ) {
Context ctx = new Context( request, channel );
request.setCorrelationId( ctx.getCorrelationId( ) );
Expand Down
Expand Up @@ -70,6 +70,7 @@
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void fireEvent( Event event ) {
doUpdate( );
}
}

private Future<?> doUpdate( ) {
if ( Bootstrap.isFinished( ) && this.canHasWrite.tryLock( ) ) {
try {
Expand All @@ -145,11 +146,13 @@ public void run( ) {
}
}
} );
}
}
if ( this.shouldReload( ) ) {
this.pendingCount.incrementAndGet( );
}
return ret != null ? ret : Futures.predestinedFuture( null );
return ret != null
? ret
: Futures.predestinedFuture( null );
} finally {
this.canHasWrite.unlock( );
}
Expand All @@ -171,18 +174,18 @@ private boolean shouldReload( ) {
return false;
}
}

public static final void restartSync( ) {
singleton.pendingCount.incrementAndGet( );
try {
singleton.doUpdate( ).get( );
} catch ( InterruptedException ex ) {
LOG.error( ex , ex );
LOG.error( ex, ex );
} catch ( ExecutionException ex ) {
LOG.error( ex , ex );
LOG.error( ex, ex );
}
}

public static final void restart( ) {
singleton.pendingCount.incrementAndGet( );
}
Expand Down Expand Up @@ -297,6 +300,13 @@ private void stop( ) {
try {
if ( this.context != null ) {
try {
for ( int i = 0; i < 10 && Contexts.hasOutstandingRequests( ); i++ ) {
try {
TimeUnit.SECONDS.sleep( 1 );
} catch ( InterruptedException ex ) {
Thread.currentThread( ).interrupt( );
}
}
this.context.stop( );
this.context.dispose( );
} catch ( MuleException ex ) {
Expand Down

0 comments on commit a981897

Please sign in to comment.