]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/spacehelpers/SpaceListenerImplBuilder.java
[XVSM] Add presentation
[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     private String name;
18     private boolean noNotification = false;
19
20     public SpaceListenerImplBuilder setCapi(Capi capi) {
21         this.capi = capi;
22         return this;
23     }
24
25     public SpaceListenerImplBuilder setCref(ContainerReference cref) {
26         this.cref = cref;
27         return this;
28     }
29
30     public SpaceListenerImplBuilder setTimeout(int timeout) {
31         this.timeout = timeout;
32         return this;
33     }
34
35     public SpaceListenerImplBuilder setSpaceAction(SpaceAction spaceAction) {
36         this.spaceAction = spaceAction;
37         return this;
38     }
39
40     public SpaceListenerImplBuilder setNotificationManager(NotificationManager mgr) {
41         this.notificationManager = mgr;
42         return this;
43     }
44
45     public SpaceListenerImplBuilder enableCountAll() {
46         this.countAll = true;
47         return this;
48     }
49
50     public SpaceListenerImplBuilder setLookaround(boolean lookaround) {
51         this.lookaround = lookaround;
52         return this;
53     }
54
55     public SpaceListenerImpl createSpaceListenerImpl() {
56         final SpaceListenerImpl spaceListener = new SpaceListenerImpl(capi, cref, timeout, spaceAction, notificationManager, lookaround, countAll, name, noNotification);
57         spaceListener.startHandlingAbsenceOfNotifications();
58         try {
59            if(! noNotification) {
60                notificationManager.createNotification(cref, spaceListener, Operation.WRITE);
61            }
62         } catch (Exception e) {
63             Util.handleSpaceErrorAndTerminate(e);
64         }
65         return spaceListener;
66     }
67
68     public SpaceListenerImplBuilder setName(String name) {
69         this.name = name;
70         return this;
71     }
72
73     public SpaceListenerImplBuilder noNotification() {
74         this.noNotification = true;
75         return this;
76     }
77 }