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.model.container.subscription.remote;
17
18 import org.apache.commons.logging.Log;
19
20 import fulmine.context.IFrameworkContext;
21 import fulmine.event.IEventSource;
22 import fulmine.event.subscription.ISubscriptionParameters;
23 import fulmine.model.container.IContainer;
24 import fulmine.model.container.subscription.ContainerSubscription;
25 import fulmine.util.log.AsyncLog;
26
27 /**
28 * Subscription for transmitting a local {@link IContainer} to a remote
29 * {@link IFrameworkContext}. This subscription is sent by a remote context to
30 * receive local container events. This is the counterpart to the
31 * {@link RxSubscription}.
32 * <p>
33 * The container(s) identified by this subscription are 'marked' for
34 * transmission by calling their
35 * {@link IRemoteSubscribable#markForRemoteSubscription()} method.
36 *
37 * @author Ramon Servadei
38 *
39 */
40 public final class TxSubscription extends ContainerSubscription
41 {
42 private final static AsyncLog LOG = new AsyncLog(TxSubscription.class);
43
44 /**
45 * Standard constructor
46 *
47 * @param parameters
48 * the parameters for the subscription
49 */
50 protected TxSubscription(ISubscriptionParameters parameters)
51 {
52 super(parameters);
53 }
54
55 @Override
56 protected boolean doAddOperation(IEventSource source)
57 {
58 if (super.doAddOperation(source))
59 {
60 IContainer container = (IContainer) source;
61 container.markForRemoteSubscription();
62 return true;
63 }
64 return false;
65 }
66
67 @Override
68 protected boolean doRemoveOperation(IEventSource source)
69 {
70 if (super.doRemoveOperation(source))
71 {
72 IContainer container = (IContainer) source;
73 container.unmarkForRemoteSubscription();
74 return true;
75 }
76 return false;
77 }
78
79 @Override
80 protected Log getLog()
81 {
82 return LOG;
83 }
84 }