]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/spacehelpers/SpaceListenerImplBuilder.java
[XVSM] Some GroupAgent Container Refactoring. Full Driver<->DeliveryCustomer communic...
[pub/jan/sbc.git] / src / main / java / at / ac / tuwien / sbc / valesriegler / xvsm / spacehelpers / SpaceListenerImplBuilder.java
1 package at.ac.tuwien.sbc.valesriegler.xvsm.spacehelpers;
2
3 import at.ac.tuwien.sbc.valesriegler.common.Util;
4 import org.mozartspaces.core.Capi;
5 import org.mozartspaces.core.ContainerReference;
6 import org.mozartspaces.notifications.NotificationManager;
7 import org.mozartspaces.notifications.Operation;
8
9 public class SpaceListenerImplBuilder {
10     private Capi capi;
11     private ContainerReference cref;
12     private int timeout = 3000;
13     private SpaceAction spaceAction;
14     private boolean lookaround = false;
15     private NotificationManager notificationManager;
16     private boolean countAll = false;
17
18     public SpaceListenerImplBuilder setCapi(Capi capi) {
19         this.capi = capi;
20         return this;
21     }
22
23     public SpaceListenerImplBuilder setCref(ContainerReference cref) {
24         this.cref = cref;
25         return this;
26     }
27
28     public SpaceListenerImplBuilder setTimeout(int timeout) {
29         this.timeout = timeout;
30         return this;
31     }
32
33     public SpaceListenerImplBuilder setSpaceAction(SpaceAction spaceAction) {
34         this.spaceAction = spaceAction;
35         return this;
36     }
37
38     public SpaceListenerImplBuilder setNotificationManager(NotificationManager mgr) {
39         this.notificationManager = mgr;
40         return this;
41     }
42
43     public SpaceListenerImplBuilder enableCountAll() {
44         this.countAll = true;
45         return this;
46     }
47
48     public SpaceListenerImplBuilder setLookaround(boolean lookaround) {
49         this.lookaround = lookaround;
50         return this;
51     }
52
53     public SpaceListenerImpl createSpaceListenerImpl() {
54         final SpaceListenerImpl spaceListener = new SpaceListenerImpl(capi, cref, timeout, spaceAction, notificationManager, lookaround, countAll);
55         spaceListener.startHandlingAbsenceOfNotifications();
56         try {
57            notificationManager.createNotification(cref, spaceListener, Operation.WRITE);
58         } catch (Exception e) {
59             Util.handleSpaceErrorAndTerminate(e);
60         }
61         return spaceListener;
62     }
63 }