/
ClientObservationManager.java
144 lines (127 loc) · 5.55 KB
/
ClientObservationManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.rmi.client;
import java.rmi.RemoteException;
import javax.jcr.RepositoryException;
import javax.jcr.UnsupportedRepositoryOperationException;
import javax.jcr.Workspace;
import javax.jcr.observation.EventJournal;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.EventListenerIterator;
import javax.jcr.observation.ObservationManager;
import org.apache.jackrabbit.rmi.iterator.ArrayEventListenerIterator;
import org.apache.jackrabbit.rmi.observation.ClientEventPoll;
import org.apache.jackrabbit.rmi.remote.RemoteObservationManager;
/**
* @deprecated RMI support is deprecated and will be removed in a future version of Jackrabbit; see <a href=https://issues.apache.org/jira/browse/JCR-4972 target=_blank>Jira ticket JCR-4972</a> for more information.
* <p>
* The <code>ClientObservationManager</code> class
* <p>
* This class uses an instance of the
* {@link org.apache.jackrabbit.rmi.observation.ClientEventPoll} class for the
* actual registration and event dispatching.
* <p>
* This class does not require the
* {@link org.apache.jackrabbit.rmi.client.LocalAdapterFactory} and consequently
* calls the base class constructor with a <code>null</code> factory.
* <p>
* See the {@link org.apache.jackrabbit.rmi.observation observation}
* package comment for a description on how event listener registration and
* notification is implemented.
*
* @see org.apache.jackrabbit.rmi.observation.ClientEventPoll
*/
@Deprecated(forRemoval = true) public class ClientObservationManager extends ClientObject implements
ObservationManager {
/** The remote observation manager */
private final RemoteObservationManager remote;
/** The <code>Workspace</code> to which this observation manager belongs. */
private final Workspace workspace;
/** The ClientEventPoll class internally used for event dispatching */
private ClientEventPoll poller;
/**
* Creates an instance of this class talking to the given remote observation
* manager.
*
* @param remote The {@link RemoteObservationManager} backing this
* client-side observation manager.
* @param workspace The <code>Workspace</code> instance to which this
* observation manager belongs.
*/
public ClientObservationManager(Workspace workspace,
RemoteObservationManager remote) {
super(null);
this.remote = remote;
this.workspace = workspace;
}
/** {@inheritDoc} */
public void addEventListener(EventListener listener, int eventTypes,
String absPath, boolean isDeep, String[] uuid,
String[] nodeTypeName, boolean noLocal)
throws RepositoryException {
try {
long listenerId = getClientEventPoll().addListener(listener);
remote.addEventListener(listenerId, eventTypes, absPath,
isDeep, uuid, nodeTypeName, noLocal);
} catch (RemoteException ex) {
throw new RemoteRepositoryException(ex);
}
}
/** {@inheritDoc} */
public void removeEventListener(EventListener listener)
throws RepositoryException {
try {
long id = getClientEventPoll().removeListener(listener);
remote.removeEventListener(id);
} catch (RemoteException ex) {
throw new RemoteRepositoryException(ex);
}
}
/** {@inheritDoc} */
public EventListenerIterator getRegisteredEventListeners() {
EventListener[] listeners = (poller != null)
? poller.getListeners()
: new EventListener[0];
return new ArrayEventListenerIterator(listeners);
}
public EventJournal getEventJournal() throws RepositoryException {
throw new UnsupportedRepositoryOperationException("TODO: JCR-3206");
}
public EventJournal getEventJournal(
int eventTypes, String absPath, boolean isDeep,
String[] uuid, String[] nodeTypeName) throws RepositoryException {
throw new UnsupportedRepositoryOperationException("TODO: JCR-3206");
}
public void setUserData(String userData) throws RepositoryException {
throw new UnsupportedRepositoryOperationException("TODO: JCR-3206");
}
//---------- internal ------------------------------------------------------
/**
* Returns the {@link ClientEventPoll} instance used by this (client-side)
* observation manager. This method creates the instance on the first call
* and starts the poller thread to wait for remote events.
*
* @return poller instance
*/
private synchronized ClientEventPoll getClientEventPoll() {
if (poller == null) {
poller = new ClientEventPoll(remote, workspace.getSession());
poller.start();
}
return poller;
}
}