]> git.somenet.org - pub/jan/sbc.git/blob - src/main/java/at/ac/tuwien/sbc/valesriegler/xvsm/spacehelpers/SpaceListenerImplBuilder.java
[XVSM] SpaceListener refactoring
[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
17     public SpaceListenerImplBuilder setCapi(Capi capi) {
18         this.capi = capi;
19         return this;
20     }
21
22     public SpaceListenerImplBuilder setCref(ContainerReference cref) {
23         this.cref = cref;
24         return this;
25     }
26
27     public SpaceListenerImplBuilder setTimeout(int timeout) {
28         this.timeout = timeout;
29         return this;
30     }
31
32     public SpaceListenerImplBuilder setSpaceAction(SpaceAction spaceAction) {
33         this.spaceAction = spaceAction;
34         return this;
35     }
36
37     public SpaceListenerImplBuilder setNotificationManager(NotificationManager mgr) {
38         this.notificationManager = mgr;
39         return this;
40     }
41
42     public SpaceListenerImplBuilder setLookaround(boolean lookaround) {
43         this.lookaround = lookaround;
44         return this;
45     }
46
47     public SpaceListenerImpl createSpaceListenerImpl() {
48         final SpaceListenerImpl spaceListener = new SpaceListenerImpl(capi, cref, timeout, spaceAction, notificationManager, lookaround);
49         spaceListener.startHandlingAbsenceOfNotifications();
50         try {
51            notificationManager.createNotification(cref, spaceListener, Operation.WRITE);
52         } catch (Exception e) {
53             Util.handleSpaceErrorAndTerminate(e);
54         }
55         return spaceListener;
56     }
57 }