Skip to content

Commit b53dbf8

Browse files
committed
new stable service description based version
stable version with changes to assume client/server have service input/output classpath
1 parent de33ed2 commit b53dbf8

File tree

3 files changed

+114
-111
lines changed

3 files changed

+114
-111
lines changed

src/org/lessrpc/ns/core/rpc/NameServerServiceProvider.java

Lines changed: 82 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.lessrpc.common.errors.ServiceNotSupportedException;
1212
import org.lessrpc.common.info.EnvironmentInfo;
1313
import org.lessrpc.common.info.SerializationFormat;
14-
import org.lessrpc.common.info.SerializedObject;
14+
import org.lessrpc.common.info.ServiceDescription;
1515
import org.lessrpc.common.info.ServiceInfo;
1616
import org.lessrpc.common.info.ServiceProviderInfo;
1717
import org.lessrpc.common.info.ServiceRequest;
@@ -32,7 +32,8 @@ public class NameServerServiceProvider implements ServiceProvider {
3232

3333
public NameServerServiceProvider(NameServer nameServer) {
3434
this.nameServer = nameServer;
35-
this.spInfo = new ServiceProviderInfo(nameServer.getURL(), nameServer.getPort(), EnvironmentInfo.currentEnvInfo());
35+
this.spInfo = new ServiceProviderInfo(nameServer.getURL(), nameServer.getPort(),
36+
EnvironmentInfo.currentEnvInfo());
3637
}
3738

3839
@Override
@@ -44,23 +45,23 @@ public boolean ping() {
4445
public ServiceResponse<?> execute(ServiceRequest request)
4546
throws ApplicationSpecificErrorException, ExecuteInternalError, InvalidArgsException,
4647
ServiceNotSupportedException, ClassNotFoundException, SQLException, DatabaseNotSupported {
47-
if (request.getService().equals(NameServerServices.GET_PROVIDER)) {
48+
if (request.getService().equals(NameServerServices.GET_PROVIDER.getInfo())) {
4849
return handleGetProviderService(request);
49-
} else if (request.getService().equals(NameServerServices.GET_PROVIDERS)) {
50+
} else if (request.getService().equals(NameServerServices.GET_PROVIDERS.getInfo())) {
5051
return handleGetProvidersService(request);
51-
} else if (request.getService().equals(NameServerServices.GET_ALL_PROVIDERS)) {
52+
} else if (request.getService().equals(NameServerServices.GET_ALL_PROVIDERS.getInfo())) {
5253
return handleGetAllProvidersService(request);
53-
} else if (request.getService().equals(NameServerServices.GET_SERVICE_INFO_BY_ID)) {
54+
} else if (request.getService().equals(NameServerServices.GET_SERVICE_INFO_BY_ID.getInfo())) {
5455
return handleGetServiceInfoById(request);
55-
} else if (request.getService().equals(NameServerServices.GET_SERVICE_INFO_BY_NAME)) {
56+
} else if (request.getService().equals(NameServerServices.GET_SERVICE_INFO_BY_NAME.getInfo())) {
5657
return handleGetServiceInfoByName(request);
57-
} else if (request.getService().equals(NameServerServices.REGISTER)) {
58+
} else if (request.getService().equals(NameServerServices.REGISTER.getInfo())) {
5859
return handleRegister(request);
59-
} else if (request.getService().equals(NameServerServices.UNREGISTER)) {
60+
} else if (request.getService().equals(NameServerServices.UNREGISTER.getInfo())) {
6061
return handleUnregister(request);
61-
} else if (request.getService().equals(NameServerServices.UNREGISTER_ALL)) {
62+
} else if (request.getService().equals(NameServerServices.UNREGISTER_ALL.getInfo())) {
6263
return handleUnregisterAll(request);
63-
} else if (request.getService().equals(NameServerServices.CHECK_PROVIDER_STATUS)) {
64+
} else if (request.getService().equals(NameServerServices.CHECK_PROVIDER_STATUS.getInfo())) {
6465
return handleCheckProviderStatus(request);
6566
}
6667
throw new ServiceNotSupportedException(request.getService());
@@ -86,7 +87,7 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
8687
}
8788
for (int i = 0; i < request.getArgs().length; i++) {
8889
// checks to make sure the provided object is not null
89-
if (request.getArgs()[i].getContent() == null) {
90+
if (request.getArgs()[i] == null) {
9091
throw new InvalidArgsException(
9192
"Required number of arguemnts was provided but the content of argument number " + i
9293
+ " object was null");
@@ -95,7 +96,7 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
9596

9697
for (int i = 0; i < request.getArgs().length; i++) {
9798
// checking if the provided object is is instance of required type
98-
if (!(types[i].isAssignableFrom(request.getArgs()[i].getContent().getClass()))) {
99+
if (!(types[i].isAssignableFrom(request.getArgs()[i].getClass()))) {
99100
throw new InvalidArgsException("Argument number " + i + " expected to have type "
100101
+ types[i].getCanonicalName() + " but an object of type "
101102
+ request.getArgs()[i].getClass().getCanonicalName() + " was provided");
@@ -106,95 +107,87 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
106107

107108
}
108109

109-
private ServiceResponse<?> handleUnregister(ServiceRequest request)
110-
throws ClassNotFoundException, SQLException, DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
110+
private ServiceResponse<?> handleUnregister(ServiceRequest request) throws ClassNotFoundException, SQLException,
111+
DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
111112
checkArgs(2, request, new Class[] { ServiceInfo.class, ServiceProviderInfo.class });
112-
boolean flag = nameServer.unregister((ServiceInfo<?>) request.getArgs()[0].getContent(),
113-
(ServiceProviderInfo) request.getArgs()[1].getContent());
113+
boolean flag = nameServer.unregister((ServiceInfo<?>) request.getArgs()[0],
114+
(ServiceProviderInfo) request.getArgs()[1]);
114115

115-
return new ServiceResponse<>(request.getService(), new SerializedObject<>(new Boolean(flag)),
116-
request.getRequestId());
116+
return new ServiceResponse<>(request.getService(), new Boolean(flag), request.getRequestId());
117117
}
118118

119-
private ServiceResponse<?> handleCheckProviderStatus(ServiceRequest request)
120-
throws ClassNotFoundException, SQLException, DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
119+
private ServiceResponse<?> handleCheckProviderStatus(ServiceRequest request) throws ClassNotFoundException,
120+
SQLException, DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
121121
checkArgs(1, request, new Class[] { ServiceProviderInfo.class });
122-
boolean flag = nameServer.checkProviderStatus((ServiceProviderInfo) request.getArgs()[0].getContent());
122+
boolean flag = nameServer.checkProviderStatus((ServiceProviderInfo) request.getArgs()[0]);
123123

124-
return new ServiceResponse<>(request.getService(), new SerializedObject<>(new Boolean(flag)),
125-
request.getRequestId());
124+
return new ServiceResponse<>(request.getService(), new Boolean(flag), request.getRequestId());
126125
}
127126

128-
private ServiceResponse<?> handleUnregisterAll(ServiceRequest request)
129-
throws ClassNotFoundException, SQLException, DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
127+
private ServiceResponse<?> handleUnregisterAll(ServiceRequest request) throws ClassNotFoundException, SQLException,
128+
DatabaseNotSupported, InvalidArgsException, ApplicationSpecificErrorException {
130129
checkArgs(1, request, new Class[] { ServiceProviderInfo.class });
131-
boolean flag = nameServer.unregisterAll((ServiceProviderInfo) request.getArgs()[0].getContent());
130+
boolean flag = nameServer.unregisterAll((ServiceProviderInfo) request.getArgs()[0]);
132131

133-
return new ServiceResponse<>(request.getService(), new SerializedObject<>(new Boolean(flag)),
134-
request.getRequestId());
132+
return new ServiceResponse<>(request.getService(), new Boolean(flag), request.getRequestId());
135133
}
136134

137-
private ServiceResponse<?> handleRegister(ServiceRequest request)
138-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
135+
private ServiceResponse<?> handleRegister(ServiceRequest request) throws InvalidArgsException,
136+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
139137
checkArgs(1, request, new Class[] { ServiceSupportInfo.class });
140-
boolean flag = nameServer.register((ServiceSupportInfo) request.getArgs()[0].getContent());
138+
boolean flag = nameServer.register((ServiceSupportInfo) request.getArgs()[0]);
141139

142-
return new ServiceResponse<>(request.getService(), new SerializedObject<>(new Boolean(flag)),
143-
request.getRequestId());
140+
return new ServiceResponse<>(request.getService(), new Boolean(flag), request.getRequestId());
144141
}
145142

146-
private ServiceResponse<?> handleGetServiceInfoByName(ServiceRequest request)
147-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
143+
private ServiceResponse<?> handleGetServiceInfoByName(ServiceRequest request) throws InvalidArgsException,
144+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
148145
checkArgs(1, request, new Class[] { String.class });
149-
ServiceInfo<?> info = nameServer.getServiceInfoByName((String) request.getArgs()[0].getContent());
146+
ServiceInfo<?> info = nameServer.getServiceInfoByName((String) request.getArgs()[0]);
150147

151-
return new ServiceResponse<ServiceInfo<?>>(request.getService(),
152-
getSerializedObject(info, ServiceInfo.class.getName()), request.getRequestId());
148+
return new ServiceResponse<ServiceInfo<?>>(request.getService(), info, request.getRequestId());
153149
}
154150

155-
private ServiceResponse<?> handleGetServiceInfoById(ServiceRequest request)
156-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
151+
private ServiceResponse<?> handleGetServiceInfoById(ServiceRequest request) throws InvalidArgsException,
152+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
157153
checkArgs(1, request, new Class[] { Integer.class });
158-
ServiceInfo<?> info = nameServer.getServiceInfoById((Integer) request.getArgs()[0].getContent());
154+
ServiceInfo<?> info = nameServer.getServiceInfoById((Integer) request.getArgs()[0]);
159155

160-
return new ServiceResponse<ServiceInfo<?>>(request.getService(),
161-
getSerializedObject(info, ServiceInfo.class.getName()), request.getRequestId());
156+
return new ServiceResponse<ServiceInfo<?>>(request.getService(), info, request.getRequestId());
162157
}
163158

164-
private ServiceResponse<?> handleGetAllProvidersService(ServiceRequest request)
165-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
159+
private ServiceResponse<?> handleGetAllProvidersService(ServiceRequest request) throws InvalidArgsException,
160+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
166161
checkArgs(0, request, new Class[] {});
167162
ServiceSupportInfo[] info = nameServer.getAllProviders();
168163

169-
return new ServiceResponse<ServiceSupportInfo[]>(request.getService(),
170-
getSerializedObject(info, ServiceSupportInfo[].class.getName()), request.getRequestId());
164+
return new ServiceResponse<ServiceSupportInfo[]>(request.getService(), info, request.getRequestId());
171165
}
172166

173-
private ServiceResponse<?> handleGetProvidersService(ServiceRequest request)
174-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
167+
private ServiceResponse<?> handleGetProvidersService(ServiceRequest request) throws InvalidArgsException,
168+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
175169
checkArgs(1, request, new Class[] { ServiceInfo.class });
176-
ServiceSupportInfo[] info = nameServer.getProviders((ServiceInfo<?>) request.getArgs()[0].getContent());
170+
ServiceSupportInfo[] info = nameServer.getProviders((ServiceInfo<?>) request.getArgs()[0]);
177171

178-
return new ServiceResponse<ServiceSupportInfo[]>(request.getService(),
179-
getSerializedObject(info, ServiceSupportInfo[].class.getName()), request.getRequestId());
172+
return new ServiceResponse<ServiceSupportInfo[]>(request.getService(), info, request.getRequestId());
180173
}
181174

182-
private ServiceResponse<?> handleGetProviderService(ServiceRequest request)
183-
throws InvalidArgsException, ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
175+
private ServiceResponse<?> handleGetProviderService(ServiceRequest request) throws InvalidArgsException,
176+
ClassNotFoundException, SQLException, DatabaseNotSupported, ApplicationSpecificErrorException {
184177
checkArgs(1, request, new Class[] { ServiceInfo.class });
185-
ServiceSupportInfo info = nameServer.getProvider((ServiceInfo<?>) request.getArgs()[0].getContent());
178+
ServiceSupportInfo info = nameServer.getProvider((ServiceInfo<?>) request.getArgs()[0]);
186179

187-
return new ServiceResponse<ServiceSupportInfo>(request.getService(),
188-
getSerializedObject(info, ServiceSupportInfo.class.getName()), request.getRequestId());
180+
return new ServiceResponse<ServiceSupportInfo>(request.getService(), info, request.getRequestId());
189181

190182
}
191183

192-
private <T extends Object> SerializedObject<T> getSerializedObject(T content, String clsPath) {
193-
if (content == null) {
194-
return new SerializedObject<>();
195-
}
196-
return new SerializedObject<>(content);
197-
}
184+
// private <T extends Object> Object<T> getObject(T
185+
// content, String clsPath) {
186+
// if (content == null) {
187+
// return new Object<>();
188+
// }
189+
// return new Object<>(content);
190+
// }
198191

199192
@Override
200193
public ServiceProviderInfo info() {
@@ -213,25 +206,41 @@ public NameServer getNameServer() {
213206
@Override
214207
public List<ServiceSupportInfo> listSupport() {
215208
List<ServiceSupportInfo> list = new ArrayList<ServiceSupportInfo>();
216-
list.add(new ServiceSupportInfo(NameServerServices.CHECK_PROVIDER_STATUS, spInfo,
209+
list.add(new ServiceSupportInfo(NameServerServices.CHECK_PROVIDER_STATUS.getInfo(), spInfo,
217210
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
218-
list.add(new ServiceSupportInfo(NameServerServices.GET_ALL_PROVIDERS, spInfo,
211+
list.add(new ServiceSupportInfo(NameServerServices.GET_ALL_PROVIDERS.getInfo(), spInfo,
219212
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
220-
list.add(new ServiceSupportInfo(NameServerServices.GET_PROVIDER, spInfo,
213+
list.add(new ServiceSupportInfo(NameServerServices.GET_PROVIDER.getInfo(), spInfo,
221214
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
222-
list.add(new ServiceSupportInfo(NameServerServices.GET_PROVIDERS, spInfo,
215+
list.add(new ServiceSupportInfo(NameServerServices.GET_PROVIDERS.getInfo(), spInfo,
223216
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
224-
list.add(new ServiceSupportInfo(NameServerServices.GET_SERVICE_INFO_BY_ID, spInfo,
217+
list.add(new ServiceSupportInfo(NameServerServices.GET_SERVICE_INFO_BY_ID.getInfo(), spInfo,
225218
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
226-
list.add(new ServiceSupportInfo(NameServerServices.GET_SERVICE_INFO_BY_NAME, spInfo,
219+
list.add(new ServiceSupportInfo(NameServerServices.GET_SERVICE_INFO_BY_NAME.getInfo(), spInfo,
227220
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
228-
list.add(new ServiceSupportInfo(NameServerServices.REGISTER, spInfo,
221+
list.add(new ServiceSupportInfo(NameServerServices.REGISTER.getInfo(), spInfo,
229222
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
230-
list.add(new ServiceSupportInfo(NameServerServices.UNREGISTER, spInfo,
223+
list.add(new ServiceSupportInfo(NameServerServices.UNREGISTER.getInfo(), spInfo,
231224
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
232-
list.add(new ServiceSupportInfo(NameServerServices.UNREGISTER_ALL, spInfo,
225+
list.add(new ServiceSupportInfo(NameServerServices.UNREGISTER_ALL.getInfo(), spInfo,
233226
new SerializationFormat[] { SerializationFormat.defaultFotmat() }));
234227
return list;
235228
}
236229

230+
@SuppressWarnings("rawtypes")
231+
@Override
232+
public List<ServiceDescription> listServices() {
233+
List<ServiceDescription> list = new ArrayList<ServiceDescription>();
234+
list.add(NameServerServices.CHECK_PROVIDER_STATUS);
235+
list.add(NameServerServices.GET_ALL_PROVIDERS);
236+
list.add(NameServerServices.GET_PROVIDER);
237+
list.add(NameServerServices.GET_PROVIDERS);
238+
list.add(NameServerServices.GET_SERVICE_INFO_BY_ID);
239+
list.add(NameServerServices.GET_SERVICE_INFO_BY_NAME);
240+
list.add(NameServerServices.REGISTER);
241+
list.add(NameServerServices.UNREGISTER);
242+
list.add(NameServerServices.UNREGISTER_ALL);
243+
return list;
244+
}
245+
237246
}

0 commit comments

Comments
 (0)