11
11
import org .lessrpc .common .errors .ServiceNotSupportedException ;
12
12
import org .lessrpc .common .info .EnvironmentInfo ;
13
13
import org .lessrpc .common .info .SerializationFormat ;
14
- import org .lessrpc .common .info .SerializedObject ;
14
+ import org .lessrpc .common .info .ServiceDescription ;
15
15
import org .lessrpc .common .info .ServiceInfo ;
16
16
import org .lessrpc .common .info .ServiceProviderInfo ;
17
17
import org .lessrpc .common .info .ServiceRequest ;
@@ -32,7 +32,8 @@ public class NameServerServiceProvider implements ServiceProvider {
32
32
33
33
public NameServerServiceProvider (NameServer nameServer ) {
34
34
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 ());
36
37
}
37
38
38
39
@ Override
@@ -44,23 +45,23 @@ public boolean ping() {
44
45
public ServiceResponse <?> execute (ServiceRequest request )
45
46
throws ApplicationSpecificErrorException , ExecuteInternalError , InvalidArgsException ,
46
47
ServiceNotSupportedException , ClassNotFoundException , SQLException , DatabaseNotSupported {
47
- if (request .getService ().equals (NameServerServices .GET_PROVIDER )) {
48
+ if (request .getService ().equals (NameServerServices .GET_PROVIDER . getInfo () )) {
48
49
return handleGetProviderService (request );
49
- } else if (request .getService ().equals (NameServerServices .GET_PROVIDERS )) {
50
+ } else if (request .getService ().equals (NameServerServices .GET_PROVIDERS . getInfo () )) {
50
51
return handleGetProvidersService (request );
51
- } else if (request .getService ().equals (NameServerServices .GET_ALL_PROVIDERS )) {
52
+ } else if (request .getService ().equals (NameServerServices .GET_ALL_PROVIDERS . getInfo () )) {
52
53
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 () )) {
54
55
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 () )) {
56
57
return handleGetServiceInfoByName (request );
57
- } else if (request .getService ().equals (NameServerServices .REGISTER )) {
58
+ } else if (request .getService ().equals (NameServerServices .REGISTER . getInfo () )) {
58
59
return handleRegister (request );
59
- } else if (request .getService ().equals (NameServerServices .UNREGISTER )) {
60
+ } else if (request .getService ().equals (NameServerServices .UNREGISTER . getInfo () )) {
60
61
return handleUnregister (request );
61
- } else if (request .getService ().equals (NameServerServices .UNREGISTER_ALL )) {
62
+ } else if (request .getService ().equals (NameServerServices .UNREGISTER_ALL . getInfo () )) {
62
63
return handleUnregisterAll (request );
63
- } else if (request .getService ().equals (NameServerServices .CHECK_PROVIDER_STATUS )) {
64
+ } else if (request .getService ().equals (NameServerServices .CHECK_PROVIDER_STATUS . getInfo () )) {
64
65
return handleCheckProviderStatus (request );
65
66
}
66
67
throw new ServiceNotSupportedException (request .getService ());
@@ -86,7 +87,7 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
86
87
}
87
88
for (int i = 0 ; i < request .getArgs ().length ; i ++) {
88
89
// checks to make sure the provided object is not null
89
- if (request .getArgs ()[i ]. getContent () == null ) {
90
+ if (request .getArgs ()[i ] == null ) {
90
91
throw new InvalidArgsException (
91
92
"Required number of arguemnts was provided but the content of argument number " + i
92
93
+ " object was null" );
@@ -95,7 +96,7 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
95
96
96
97
for (int i = 0 ; i < request .getArgs ().length ; i ++) {
97
98
// 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 ()))) {
99
100
throw new InvalidArgsException ("Argument number " + i + " expected to have type "
100
101
+ types [i ].getCanonicalName () + " but an object of type "
101
102
+ request .getArgs ()[i ].getClass ().getCanonicalName () + " was provided" );
@@ -106,95 +107,87 @@ private boolean checkArgs(int requiredArgs, ServiceRequest request, Class<?>[] t
106
107
107
108
}
108
109
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 {
111
112
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 ]);
114
115
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 ());
117
117
}
118
118
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 {
121
121
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 ]);
123
123
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 ());
126
125
}
127
126
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 {
130
129
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 ]);
132
131
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 ());
135
133
}
136
134
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 {
139
137
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 ]);
141
139
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 ());
144
141
}
145
142
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 {
148
145
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 ]);
150
147
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 ());
153
149
}
154
150
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 {
157
153
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 ]);
159
155
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 ());
162
157
}
163
158
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 {
166
161
checkArgs (0 , request , new Class [] {});
167
162
ServiceSupportInfo [] info = nameServer .getAllProviders ();
168
163
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 ());
171
165
}
172
166
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 {
175
169
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 ]);
177
171
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 ());
180
173
}
181
174
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 {
184
177
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 ]);
186
179
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 ());
189
181
190
182
}
191
183
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
+ // }
198
191
199
192
@ Override
200
193
public ServiceProviderInfo info () {
@@ -213,25 +206,41 @@ public NameServer getNameServer() {
213
206
@ Override
214
207
public List <ServiceSupportInfo > listSupport () {
215
208
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 ,
217
210
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 ,
219
212
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
220
- list .add (new ServiceSupportInfo (NameServerServices .GET_PROVIDER , spInfo ,
213
+ list .add (new ServiceSupportInfo (NameServerServices .GET_PROVIDER . getInfo () , spInfo ,
221
214
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
222
- list .add (new ServiceSupportInfo (NameServerServices .GET_PROVIDERS , spInfo ,
215
+ list .add (new ServiceSupportInfo (NameServerServices .GET_PROVIDERS . getInfo () , spInfo ,
223
216
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 ,
225
218
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 ,
227
220
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
228
- list .add (new ServiceSupportInfo (NameServerServices .REGISTER , spInfo ,
221
+ list .add (new ServiceSupportInfo (NameServerServices .REGISTER . getInfo () , spInfo ,
229
222
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
230
- list .add (new ServiceSupportInfo (NameServerServices .UNREGISTER , spInfo ,
223
+ list .add (new ServiceSupportInfo (NameServerServices .UNREGISTER . getInfo () , spInfo ,
231
224
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
232
- list .add (new ServiceSupportInfo (NameServerServices .UNREGISTER_ALL , spInfo ,
225
+ list .add (new ServiceSupportInfo (NameServerServices .UNREGISTER_ALL . getInfo () , spInfo ,
233
226
new SerializationFormat [] { SerializationFormat .defaultFotmat () }));
234
227
return list ;
235
228
}
236
229
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
+
237
246
}
0 commit comments