~ubuntu-branches/ubuntu/vivid/eucalyptus/vivid

« back to all changes in this revision

Viewing changes to .pc/26-google-collections-1.0-ftbfs.patch/clc/modules/cluster-manager/src/main/java/com/eucalyptus/cluster/callback/StateUpdateHandler.java

  • Committer: Bazaar Package Importer
  • Author(s): James Page
  • Date: 2011-05-18 10:46:58 UTC
  • Revision ID: james.westby@ubuntu.com-20110518104658-umi4lvp0yqtu8cl9
Tags: 2.0.1+bzr1256-0ubuntu5
* Fix FTBFS against libgoogle-collections-java 1.0 (LP: #784491). 
  - debian/patches/26-google-collections-1.0-ftbfs.patch: refactoring
    to use 1.0 API.
* Fix libjibx-java to version 1.1 to allow entry of libjibx1.2-java 
  into universe without breaking eucalyptus:
  - debian/eucalyptus-java-common.links: use jibx-*-1.1.jar.
  - debian/build-jars: use jibx-*-1.1.jar.
  - debian/control: use libjibx1.1-java instead of libjibx-java.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.cluster.callback;
 
2
 
 
3
import java.util.concurrent.ConcurrentMap;
 
4
import java.util.concurrent.atomic.AtomicBoolean;
 
5
import org.apache.log4j.Logger;
 
6
import com.eucalyptus.cluster.Cluster;
 
7
import com.eucalyptus.event.ClockTick;
 
8
import com.eucalyptus.event.Event;
 
9
import com.eucalyptus.event.EventListener;
 
10
import com.eucalyptus.records.EventRecord;
 
11
import com.eucalyptus.records.EventType;
 
12
import com.google.common.base.Predicate;
 
13
import com.google.common.collect.Iterables;
 
14
import com.google.common.collect.Maps;
 
15
 
 
16
public class StateUpdateHandler implements EventListener {
 
17
  private static Logger LOG = Logger.getLogger( StateUpdateHandler.class );
 
18
  private static final ConcurrentMap<String,StateUpdateHandler> clusterMap = Maps.newConcurrentHashMap( );
 
19
  private final ConcurrentMap<Class,AtomicBoolean> inflightMap = Maps.newConcurrentHashMap( );
 
20
  private final ConcurrentMap<Class,QueuedEventCallback> callbackMap = Maps.newConcurrentHashMap( );
 
21
  private final Cluster cluster;
 
22
  
 
23
  public static void create( Cluster cluster, QueuedEventCallback callback ) {
 
24
    StateUpdateHandler handler = new StateUpdateHandler( cluster );
 
25
    StateUpdateHandler.clusterMap.putIfAbsent( cluster.getName( ), handler );
 
26
    handler = StateUpdateHandler.clusterMap.get( cluster.getName( ) );
 
27
    EventRecord.here( StateUpdateHandler.class, EventType.CLUSTER_STATE_HANDLER_REGISTERED, cluster.getName( ), callback.getClass( ).getCanonicalName( ) );
 
28
  }
 
29
  
 
30
  private StateUpdateHandler( Cluster cluster ) {
 
31
    this.cluster = cluster;
 
32
  }
 
33
 
 
34
  public boolean timedTrigger( Event c ) {
 
35
    if ( c instanceof ClockTick ) {
 
36
      return ( ( ClockTick ) c ).isBackEdge( );
 
37
    } else {
 
38
      return false;
 
39
    }
 
40
  }
 
41
 
 
42
  public void addCallback( QueuedEventCallback cb ) {
 
43
    if( this.callbackMap.putIfAbsent( cb.getClass( ), cb ) == null ) {
 
44
      this.inflightMap.put( cb.getClass( ), new AtomicBoolean( false ) );
 
45
    } else {
 
46
      LOG.debug( "Ignoring addition of timed callback for cluster "+ this.cluster.getName( )+ " which is already configured: " + cb.getClass( ) );
 
47
    }
 
48
  }
 
49
  
 
50
  @Override
 
51
  public void advertiseEvent( Event event ) {}
 
52
 
 
53
  @Override
 
54
  public void fireEvent( Event event ) {
 
55
    if( this.timedTrigger( event ) ) {
 
56
      Iterables.all( callbackMap.keySet( ), new Predicate<Class>() {
 
57
 
 
58
        @Override
 
59
        public boolean apply( Class arg0 ) {
 
60
          if( StateUpdateHandler.this.inflightMap.get( arg0 ).compareAndSet( false, true ) ) {
 
61
            //TODO: RELEASE: wrap this up here.
 
62
          }
 
63
          return false;
 
64
        }} );
 
65
    }
 
66
  }
 
67
 
 
68
}