use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.
the class LeshanClusterServer method createAndStartServer.
public static void createAndStartServer(String clusterInstanceId, String localAddress, int localPort, String secureLocalAddress, int secureLocalPort, String modelsFolderPath, String redisUrl) throws Exception {
// Create Redis connector.
// TODO: support sentinel pool and make pool configurable
Pool<Jedis> jedis = new JedisPool(new URI(redisUrl));
// Prepare LWM2M server.
LeshanServerBuilder builder = new LeshanServerBuilder();
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
builder.setDecoder(decoder);
builder.setCoapConfig(NetworkConfig.getStandard());
List<ObjectModel> models = ObjectLoader.loadDefault();
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath)));
}
LwM2mModelProvider modelProvider = new StaticModelProvider(models);
builder.setObjectModelProvider(modelProvider);
RedisRegistrationStore registrationStore = new RedisRegistrationStore(jedis);
builder.setRegistrationStore(registrationStore);
// TODO add support of public and private server key
builder.setSecurityStore(new RedisSecurityStore(jedis));
// Create and start LWM2M server
LeshanServer lwServer = builder.build();
// Create Clustering support
RedisTokenHandler tokenHandler = new RedisTokenHandler(jedis, clusterInstanceId);
new RedisRequestResponseHandler(jedis, lwServer, lwServer.getRegistrationService(), tokenHandler, lwServer.getObservationService());
lwServer.getRegistrationService().addListener(tokenHandler);
lwServer.getRegistrationService().addListener(new RedisRegistrationEventPublisher(jedis));
// Start Jetty & Leshan
lwServer.start();
}
use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.
the class RedisSecureIntegrationTestHelper method createServer.
@Override
public void createServer() {
LeshanServerBuilder builder = new LeshanServerBuilder();
StaticModelProvider modelProvider = new StaticModelProvider(createObjectModels());
builder.setObjectModelProvider(modelProvider);
DefaultLwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
builder.setDecoder(decoder);
builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
// Create redis store
String redisURI = System.getenv("REDIS_URI");
if (redisURI == null)
redisURI = "";
Pool<Jedis> jedis = new JedisPool(redisURI);
builder.setRegistrationStore(new RedisRegistrationStore(jedis));
builder.setSecurityStore(new RedisSecurityStore(jedis));
// Build server !
server = builder.build();
// monitor client registration
resetLatch();
server.getRegistrationService().addListener(new RegistrationListener() {
@Override
public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) {
if (updatedRegistration.getEndpoint().equals(getCurrentEndpoint())) {
updateLatch.countDown();
}
}
@Override
public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, Registration newReg) {
if (registration.getEndpoint().equals(getCurrentEndpoint())) {
deregisterLatch.countDown();
}
}
@Override
public void registered(Registration registration, Registration previousReg, Collection<Observation> previousObsersations) {
if (registration.getEndpoint().equals(getCurrentEndpoint())) {
last_registration = registration;
registerLatch.countDown();
}
}
});
}
use of org.eclipse.leshan.server.californium.LeshanServerBuilder in project leshan by eclipse.
the class SecureIntegrationTestHelper method createServerWithX509Cert.
public void createServerWithX509Cert(Certificate[] trustedCertificates) {
LeshanServerBuilder builder = new LeshanServerBuilder();
builder.setLocalAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
builder.setLocalSecureAddress(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0));
builder.setPrivateKey(serverPrivateKeyFromCert);
builder.setCertificateChain(serverX509CertChain);
builder.setTrustedCertificates(trustedCertificates);
builder.setSecurityStore(new InMemorySecurityStore());
server = builder.build();
// monitor client registration
setupRegistrationMonitoring();
}
Aggregations