Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
use the timeout. gdmit.
Browse files Browse the repository at this point in the history
  • Loading branch information
chris grzegorczyk committed Jan 6, 2012
1 parent c55b240 commit d25f654
Showing 1 changed file with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@

import java.util.Date;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.persistence.CollectionTable;
Expand Down Expand Up @@ -148,7 +149,7 @@ private void addReasonDetail( final String... extra ) {

public void setState( final VmState newState, Reason reason, final String... extra ) {
final VmState oldState = this.getVmInstance( ).getState( );
Runnable action = null;
Callable<Boolean> action = null;
if ( VmStateSet.RUN.contains( newState ) && VmStateSet.NOT_RUNNING.contains( oldState ) ) {
action = this.cleanUpRunnable( SEND_USER_TERMINATE );
} else if ( !oldState.equals( newState ) ) {
Expand All @@ -167,15 +168,18 @@ public void setState( final VmState newState, Reason reason, final String... ext
this.addReasonDetail( extra );
this.reason = reason;
try {
Threads.lookup( Eucalyptus.class, VmInstance.class ).limitTo( VmInstances.MAX_STATE_THREADS ).submit( action ).get( );//10, TimeUnit.MILLISECONDS );//GRZE:wtf?! why short time limit.
Threads.enqueue( Eucalyptus.class, VmInstance.class, VmInstances.MAX_STATE_THREADS, action ).get( 10, TimeUnit.MILLISECONDS );//GRZE: yes. wait for 10ms. because.
} catch ( final TimeoutException ex ) {
} catch ( final InterruptedException ex ) {
} catch ( final Exception ex ) {
LOG.error( ex, ex );
LOG.error( ex );
Logs.extreme( ).error( ex, ex );
}
}
}

private Runnable handleStateTransition( final VmState newState, final VmState oldState ) {
Runnable action = null;
private Callable<Boolean> handleStateTransition( final VmState newState, final VmState oldState ) {
Callable<Boolean> action = null;
LOG.info( String.format( "%s state change: %s -> %s", this.getVmInstance( ).getInstanceId( ), this.getVmInstance( ).getState( ), newState ) );
if ( VmStateSet.RUN.contains( oldState ) && VmStateSet.NOT_RUNNING.contains( newState ) ) {
this.getVmInstance( ).setState( newState );
Expand All @@ -202,18 +206,19 @@ private Runnable handleStateTransition( final VmState newState, final VmState ol
return action;
}

private Runnable cleanUpRunnable( ) {
private Callable<Boolean> cleanUpRunnable( ) {
return this.cleanUpRunnable( null );
}

private Runnable cleanUpRunnable( final String reason ) {
return new Runnable( ) {
private Callable<Boolean> cleanUpRunnable( final String reason ) {
return new Callable<Boolean>( ) {
@Override
public void run( ) {
public Boolean call( ) {
VmInstances.cleanUp( VmRuntimeState.this.getVmInstance( ) );
if ( ( reason != null ) && !VmRuntimeState.this.reasonDetails.contains( reason ) ) {
VmRuntimeState.this.addReasonDetail( reason );
}
return Boolean.TRUE;
}
};
}
Expand Down

0 comments on commit d25f654

Please sign in to comment.