本文整理汇总了Java中org.eclipse.leshan.client.resource.ObjectsInitializer类的典型用法代码示例。如果您正苦于以下问题:Java ObjectsInitializer类的具体用法?Java ObjectsInitializer怎么用?Java ObjectsInitializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectsInitializer类属于org.eclipse.leshan.client.resource包,在下文中一共展示了ObjectsInitializer类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createX509CertClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public void createX509CertClient(PrivateKey privatekey, Certificate[] trustedCertificates) {
ObjectsInitializer initializer = new ObjectsInitializer();
// TODO security instance with certificate info
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
"coaps://" + server.getSecuredAddress().getHostString() + ":" + server.getSecuredAddress().getPort(),
12345));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
// TODO we should read the config from the security object
config.setIdentity(privatekey, clientX509CertChain, false);
config.setTrustStore(trustedCertificates);
CoapServer coapServer = new CoapServer();
coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
client = builder.build();
}
示例2: createClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public void createClient() {
// Create objects Enabler
ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(createObjectModels()));
initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec(
"coap://" + server.getUnsecuredAddress().getHostString() + ":" + server.getUnsecuredAddress().getPort(),
12345));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U") {
@Override
public ExecuteResponse execute(int resourceid, String params) {
if (resourceid == 4) {
return ExecuteResponse.success();
} else {
return super.execute(resourceid, params);
}
}
});
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.addAll(initializer.create(2, 2000));
// Build Client
LeshanClientBuilder builder = new LeshanClientBuilder(currentEndpointIdentifier.get());
builder.setObjects(objects);
client = builder.build();
}
示例3: createPSKClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public void createPSKClient() {
ObjectsInitializer initializer = new ObjectsInitializer();
initializer.setInstancesForObject(LwM2mId.SECURITY,
Security.psk(
"coaps://" + server.getSecuredAddress().getHostString() + ":"
+ server.getSecuredAddress().getPort(),
12345, GOOD_PSK_ID.getBytes(StandardCharsets.UTF_8), GOOD_PSK_KEY));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
client = builder.build();
}
示例4: createClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
private void createClient(Security security) {
ObjectsInitializer initializer = new ObjectsInitializer();
// Initialize LWM2M Object Tree
initializer.setInstancesForObject(LwM2mId.SECURITY, security);
initializer.setInstancesForObject(LwM2mId.DEVICE,
new Device("Eclipse Leshan", IntegrationTestHelper.MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
// Create Leshan Client
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setObjects(objects);
client = builder.build();
}
示例5: createRPKClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public void createRPKClient() {
ObjectsInitializer initializer = new ObjectsInitializer();
initializer.setInstancesForObject(LwM2mId.SECURITY,
Security.rpk(
"coaps://" + server.getSecuredAddress().getHostString() + ":"
+ server.getSecuredAddress().getPort(),
12345, clientPublicKey.getEncoded(), clientPrivateKey.getEncoded(),
serverPublicKey.getEncoded()));
initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U"));
List<LwM2mObjectEnabler> objects = initializer.createMandatory();
objects.add(initializer.create(2));
InetSocketAddress clientAddress = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0);
DtlsConnectorConfig.Builder config = new DtlsConnectorConfig.Builder().setAddress(clientAddress);
// TODO we should read the config from the security object
// TODO no way to provide a dynamic config with the current scandium API
config.setIdentity(clientPrivateKey, clientPublicKey);
CoapServer coapServer = new CoapServer();
coapServer.addEndpoint(new CoapEndpoint(new DTLSConnector(config.build()), NetworkConfig.getStandard()));
LeshanClientBuilder builder = new LeshanClientBuilder(getCurrentEndpoint());
builder.setLocalAddress(clientAddress.getHostString(), clientAddress.getPort());
builder.setObjects(objects);
client = builder.build();
}
示例6: main
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public static void main(final String[] args) {
if(ConfigLoader.LoadFile()){
SerialConnector sc = new SerialConnector();
TemperatureSensor tempSensor = new TemperatureSensor(sc);
HumiditySensor humiSensor = new HumiditySensor(sc);
LightActuator lightActuator = new LightActuator(sc);
// Get endpoint name
String endpoint = DEFAULT_ENDPOINT;
// Get server URI
String serverURI="coap://localhost:5083";
// byte[] pskIdentity = null;
// byte[] pskKey = null;
// get local address
String localAddress = "localhost";
int localPort = 6000;
// get secure local address
String secureLocalAddress = "localhost";
int secureLocalPort = 6001;
sc.start();
// Initialize object list
ObjectsInitializer initializer = new ObjectsInitializer();
initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
initializer.setClassForObject(DEVICE, KETIVirtualDevice.class);
initializer.setInstancesForObject(3303, tempSensor);
initializer.setInstancesForObject(3304, humiSensor);
initializer.setInstancesForObject(3311, lightActuator);
List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, 3303, 3304, 3311);
// Create client
LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setObjects(enablers);
final LeshanClient client = builder.build();
// Start the client
client.start();
// De-register on shutdown and stop client.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
client.destroy(true); // send de-registration request before destroy
}
});
} else {
LOG.error("Can not found the port.conf file!");
}
}
示例7: createAndStartClient
import org.eclipse.leshan.client.resource.ObjectsInitializer; //导入依赖的package包/类
public static void createAndStartClient(String endpoint, String localAddress, int localPort,
String secureLocalAddress, int secureLocalPort, boolean needBootstrap, String serverURI, byte[] pskIdentity,
byte[] pskKey) {
// Initialize object list
ObjectsInitializer initializer = new ObjectsInitializer();
if (needBootstrap) {
if (pskIdentity == null)
initializer.setInstancesForObject(SECURITY, noSecBootstap(serverURI));
else
initializer.setInstancesForObject(SECURITY, pskBootstrap(serverURI, pskIdentity, pskKey));
} else {
if (pskIdentity == null) {
initializer.setInstancesForObject(SECURITY, noSec(serverURI, 123));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
} else {
initializer.setInstancesForObject(SECURITY, psk(serverURI, 123, pskIdentity, pskKey));
initializer.setInstancesForObject(SERVER, new Server(123, 30, BindingMode.U, false));
}
}
initializer.setClassForObject(DEVICE, MyDevice.class);
initializer.setInstancesForObject(LOCATION, locationInstance);
List<LwM2mObjectEnabler> enablers = initializer.create(SECURITY, SERVER, DEVICE, CONNECTIVITY_MONITORING, LOCATION, CONNECTIVITY_STATISTICS);
// Create client
LeshanClientBuilder builder = new LeshanClientBuilder(endpoint);
builder.setLocalAddress(localAddress, localPort);
builder.setLocalSecureAddress(secureLocalAddress, secureLocalPort);
builder.setObjects(enablers);
final LeshanClient client = builder.build();
LOG.info("Press 'w','a','s','d' to change reported Location.");
// Start the client
client.start();
// De-register on shutdown and stop client.
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
client.destroy(true); // send de-registration request before destroy
}
});
// Change the location through the Console
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String nextMove = scanner.next();
locationInstance.moveLocation(nextMove);
}
scanner.close();
}