当前位置: 首页>>代码示例>>Java>>正文


Java ObjectsInitializer.setInstancesForObject方法代码示例

本文整理汇总了Java中org.eclipse.leshan.client.resource.ObjectsInitializer.setInstancesForObject方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectsInitializer.setInstancesForObject方法的具体用法?Java ObjectsInitializer.setInstancesForObject怎么用?Java ObjectsInitializer.setInstancesForObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.leshan.client.resource.ObjectsInitializer的用法示例。


在下文中一共展示了ObjectsInitializer.setInstancesForObject方法的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();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:26,代码来源:SecureIntegrationTestHelper.java

示例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();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:26,代码来源:IntegrationTestHelper.java

示例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();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:19,代码来源:SecureIntegrationTestHelper.java

示例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();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:16,代码来源:BootstrapIntegrationTestHelper.java

示例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();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:28,代码来源:SecureIntegrationTestHelper.java

示例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!");
    	}
    }
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:63,代码来源:DeviceClient.java

示例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();
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:53,代码来源:LeshanClientDemo.java


注:本文中的org.eclipse.leshan.client.resource.ObjectsInitializer.setInstancesForObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。