blob: 97038fc50f6008f89b8a8c9de29e6afdc52cabfd (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2010-2011 Composent, Inc. and others. All rights reserved. This
* program and the accompanying materials are made available under the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Composent, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.ecf.osgi.services.remoteserviceadmin;
import org.eclipse.core.runtime.Assert;
import org.eclipse.ecf.remoteservice.IRemoteServiceRegistration;
import org.osgi.framework.ServiceReference;
public class ExportRegistration implements
org.osgi.service.remoteserviceadmin.ExportRegistration {
private IRemoteServiceRegistration rsRegistration;
private ExportReference exportReference;
private Throwable throwable;
private final Object closeLock = new Object();
public ExportRegistration(IRemoteServiceRegistration rsRegistration,
ServiceReference serviceReference,
EndpointDescription endpointDescription) {
Assert.isNotNull(rsRegistration);
this.rsRegistration = rsRegistration;
this.exportReference = new ExportReference(serviceReference,
endpointDescription);
}
public ExportRegistration(Throwable t) {
this.throwable = t;
}
public org.osgi.service.remoteserviceadmin.ExportReference getExportReference() {
synchronized (closeLock) {
Throwable t = getException();
if (t != null)
throw new IllegalStateException(
"Cannot get export reference as registration not properly initialized",
t);
return exportReference;
}
}
public boolean matchesServiceReference(ServiceReference serviceReference) {
if (serviceReference == null)
return false;
synchronized (closeLock) {
if (exportReference == null)
return false;
ServiceReference sr = exportReference.getExportedService();
if (sr.equals(serviceReference))
return true;
else
return false;
}
}
public IRemoteServiceRegistration getRemoteServiceRegistration() {
return rsRegistration;
}
public void close() {
synchronized (closeLock) {
if (rsRegistration != null) {
rsRegistration.unregister();
rsRegistration = null;
}
if (exportReference != null) {
exportReference.close();
exportReference = null;
}
throwable = null;
}
}
public Throwable getException() {
synchronized (closeLock) {
return throwable;
}
}
public String toString() {
synchronized (closeLock) {
return "ExportRegistration[rsRegistration=" + rsRegistration
+ ", exportReference=" + exportReference + ", throwable="
+ throwable + "]";
}
}
}
|