View Javadoc

1   /*
2      Copyright 2008 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.context;
17  
18  import fulmine.IDomain;
19  import fulmine.IType;
20  import fulmine.event.listener.IEventListener;
21  import fulmine.event.subscription.SubscriptionParameters;
22  
23  /**
24   * A {@link DistributionManager} for an {@link FTContext}. This takes over the
25   * subscription and unsubscription implementations and only issues remote
26   * subscriptions if the FT context is not active, otherwise normal behaviour
27   * continues.
28   * 
29   * @author Ramon Servadei
30   */
31  public class FTDistributionManager extends DistributionManager
32  {
33  
34      /** The FTContext */
35      private final FTContext ftContext;
36  
37      public FTDistributionManager(IFrameworkContext context, FTContext ftContext)
38      {
39          super(context);
40          this.ftContext = ftContext;
41      }
42  
43      @Override
44      public boolean subscribe(String contextIdentity, String identityRegex,
45          IType type, IDomain domain, IEventListener listener)
46      {
47          if (this.ftContext.isFTContextActive())
48          {
49              return super.subscribe(contextIdentity, identityRegex, type,
50                  domain, listener);
51          }
52          return super.doRemoteSubscribe(contextIdentity,
53              new SubscriptionParameters(identityRegex, type, domain), listener);
54      }
55  
56      @Override
57      public boolean unsubscribe(String contextIdentity, String identityRegex,
58          IType type, IDomain domain, IEventListener listener)
59      {
60          if (this.ftContext.isFTContextActive())
61          {
62              return super.unsubscribe(contextIdentity, identityRegex, type,
63                  domain, listener);
64          }
65          return super.doRemoteUnsubscribe(contextIdentity,
66              new SubscriptionParameters(identityRegex, type, domain), listener);
67      }
68  
69  }