use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class PresenceServiceTest method givenASimpleClient.
private Registration givenASimpleClient() throws UnknownHostException {
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 5683);
Registration.Builder builder = new Registration.Builder("ID", "urn:client", Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), address);
Registration reg = builder.build();
presenceService.setAwake(reg);
return reg;
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class PresenceServiceTest method givenASimpleClientWithQueueMode.
private Registration givenASimpleClientWithQueueMode() throws UnknownHostException {
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 5683);
Registration.Builder builder = new Registration.Builder("ID", "urn:client", Identity.unsecure(Inet4Address.getLoopbackAddress(), 12354), address);
Registration reg = builder.bindingMode(BindingMode.UQ).build();
presenceService.setAwake(reg);
return reg;
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class ClientServlet method doDelete.
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String[] path = StringUtils.split(req.getPathInfo(), '/');
String clientEndpoint = path[0];
// /clients/endPoint/LWRequest/observe : cancel observation for the given resource.
if (path.length >= 3 && "observe".equals(path[path.length - 1])) {
try {
String target = StringUtils.substringsBetween(req.getPathInfo(), clientEndpoint, "/observe")[0];
Registration registration = server.getRegistrationService().getByEndpoint(clientEndpoint);
if (registration != null) {
server.getObservationService().cancelObservations(registration, target);
resp.setStatus(HttpServletResponse.SC_OK);
} else {
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
resp.getWriter().format("no registered client with id '%s'", clientEndpoint).flush();
}
} catch (RuntimeException e) {
handleException(e, resp);
}
return;
}
// /clients/endPoint/LWRequest/ : delete instance
try {
String target = StringUtils.removeStart(req.getPathInfo(), "/" + clientEndpoint);
Registration registration = server.getRegistrationService().getByEndpoint(clientEndpoint);
if (registration != null) {
DeleteRequest request = new DeleteRequest(target);
DeleteResponse cResponse = server.send(registration, request, TIMEOUT);
processDeviceResponse(req, resp, cResponse);
} else {
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
resp.getWriter().format("no registered client with id '%s'", clientEndpoint).flush();
}
} catch (RuntimeException | InterruptedException e) {
handleException(e, resp);
}
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class CaliforniumLwM2mBootstrapRequestSender method send.
@Override
public <T extends LwM2mResponse> T send(final String endpointName, final Identity destination, final DownlinkRequest<T> request, long timeout) throws InterruptedException {
// Create the CoAP request
// from LwM2m request
CoapRequestBuilder coapClientRequestBuilder = new CoapRequestBuilder(destination, model, encoder);
request.accept(coapClientRequestBuilder);
final Request coapRequest = coapClientRequestBuilder.getRequest();
// Send CoAP request synchronously
SyncRequestObserver<T> syncMessageObserver = new SyncRequestObserver<T>(coapRequest, timeout) {
@Override
public T buildResponse(Response coapResponse) {
// TODO we need to fix that by removing the Client dependency from LwM2MResponseBuilder or by creating a
// LwM2mBootstrapResponseBuilder
Registration registration = new Registration.Builder("fakeregistrationid", endpointName, destination, destination.isSecure() ? secureEndpoint.getAddress() : nonSecureEndpoint.getAddress()).build();
// Build LwM2m response
LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse, registration, model, null, decoder);
request.accept(lwm2mResponseBuilder);
return lwm2mResponseBuilder.getResponse();
}
};
coapRequest.addMessageObserver(syncMessageObserver);
// Send CoAP request asynchronously
if (destination.isSecure())
secureEndpoint.sendRequest(coapRequest);
else
nonSecureEndpoint.sendRequest(coapRequest);
// Wait for response, then return it
return syncMessageObserver.waitForResponse();
}
use of org.eclipse.leshan.server.registration.Registration in project leshan by eclipse.
the class InMemoryRegistrationStore method removeRegistration.
@Override
public Deregistration removeRegistration(String registrationId) {
try {
lock.writeLock().lock();
Registration registration = getRegistration(registrationId);
if (registration != null) {
Collection<Observation> observationsRemoved = unsafeRemoveAllObservations(registration.getId());
regsByEp.remove(registration.getEndpoint());
return new Deregistration(registration, observationsRemoved);
}
return null;
} finally {
lock.writeLock().unlock();
}
}
Aggregations