• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Endpoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.californium.core.network.Endpoint的典型用法代码示例。如果您正苦于以下问题:Java Endpoint类的具体用法?Java Endpoint怎么用?Java Endpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Endpoint类属于org.eclipse.californium.core.network包,在下文中一共展示了Endpoint类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: EventServlet

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
public EventServlet(LeshanServer server, int securePort) {
    server.getRegistrationService().addListener(this.registrationListener);
    server.getObservationService().addListener(this.observationListener);

    // add an interceptor to each endpoint to trace all CoAP messages
    coapMessageTracer = new CoapMessageTracer(server.getRegistrationService());
    for (Endpoint endpoint : server.getCoapServer().getEndpoints()) {
        endpoint.addInterceptor(coapMessageTracer);
    }

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeHierarchyAdapter(Registration.class, new RegistrationSerializer(securePort));
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
    gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    this.gson = gsonBuilder.create();
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:17,代码来源:EventServlet.java


示例2: getEffectiveEndpoint

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Returns the effective endpoint that the specified request is supposed to
 * be sent over. If an endpoint has explicitly been set to this CoapClient,
 * this endpoint will be used. If no endpoint has been set, the client will
 * effectively use a default endpoint of the {@link EndpointManager}.
 * 
 * @param request the request to be sent
 * @return the effective endpoint that the request is going o be sent over.
 */
protected Endpoint getEffectiveEndpoint(Request request) {
	Endpoint myEndpoint = getEndpoint();
	
	// custom endpoint
	if (myEndpoint != null) return myEndpoint;
	
	// default endpoints
	if (CoAP.COAP_SECURE_URI_SCHEME.equals(request.getScheme())) {
		// this is the case when secure coap is supposed to be used
		return EndpointManager.getEndpointManager().getDefaultSecureEndpoint();
	} else {
		// this is the normal case
		return EndpointManager.getEndpointManager().getDefaultEndpoint();
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:25,代码来源:CoapClient.java


示例3: setEndpoint

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Sets the endpoint this client is supposed to use.
 *
 * @param endpoint the endpoint
 * @return the CoAP client
 */
public CoapClient setEndpoint(Endpoint endpoint) {
			
	this.endpoint = endpoint;
	
	if (!endpoint.isStarted()) {
		try {
			endpoint.start();
			LOGGER.log(Level.INFO, "Started set client endpoint " + endpoint.getAddress());
		} catch (IOException e) {
			LOGGER.log(Level.SEVERE, "Could not set and start client endpoint", e);
		}
		
	}
	
	return this;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:23,代码来源:CoapClient.java


示例4: EventServlet

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
public EventServlet(LeshanServer server, int securePort) {
    this.server = server;
    server.getClientRegistry().addListener(this.clientRegistryListener);
    server.getObservationRegistry().addListener(this.observationRegistryListener);

    // add an interceptor to each endpoint to trace all CoAP messages
    coapMessageTracer = new CoapMessageTracer(server.getClientRegistry());
    for (Endpoint endpoint : server.getCoapServer().getEndpoints()) {
        endpoint.addInterceptor(coapMessageTracer);
    }

    GsonBuilder gsonBuilder = new GsonBuilder();
    gsonBuilder.registerTypeHierarchyAdapter(Client.class, new ClientSerializer(securePort));
    gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
    gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    this.gson = gsonBuilder.create();
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:18,代码来源:EventServlet.java


示例5: AllInterfacesCoapServer

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Creates a new AllInterfacesCoapServer which listens on all available IP addresses.
 */
public AllInterfacesCoapServer() {
	addEndpoints();
	start();

	String interfaces = getEndpoints().stream().
			map(Endpoint::getAddress).
			map(a -> "[" + a.getHostString() + ":" + a.getPort() + "]")
			.collect(Collectors.joining(", "));


	logger.info("DCAF server running on " + interfaces + ".");
}
 
开发者ID:beduino-project,项目名称:dcaf-java,代码行数:16,代码来源:AllInterfacesCoapServer.java


示例6: synchronous

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
private CoapResponse synchronous(Request request, Endpoint outEndpoint) {
	try {
		Response response = send(request, outEndpoint).waitForResponse(getTimeout());
		if (response == null) return null;
		else return new CoapResponse(response);
	} catch (InterruptedException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:10,代码来源:CoapClient.java


示例7: observeAndWait

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
private CoapObserveRelation observeAndWait(Request request, CoapHandler handler) {
	Endpoint outEndpoint = getEffectiveEndpoint(request);
	CoapObserveRelation relation = new CoapObserveRelation(request, outEndpoint);
	request.addMessageObserver(new ObserveMessageObserverImpl(handler, relation));
	CoapResponse response = synchronous(request, outEndpoint);
	if (response == null || !response.advanced().getOptions().hasObserve())
		relation.setCanceled(true);
	relation.setCurrent(response);
	return relation;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:CoapClient.java


示例8: observe

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
private CoapObserveRelation observe(Request request, CoapHandler handler) {
	Endpoint outEndpoint = getEffectiveEndpoint(request);
	CoapObserveRelation relation = new CoapObserveRelation(request, outEndpoint);
	request.addMessageObserver(new ObserveMessageObserverImpl(handler, relation));
	send(request, outEndpoint);
	return relation;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:8,代码来源:CoapClient.java


示例9: send

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Sends the specified request over the specified endpoint.
 * 
 * @param request the request
 * @param outEndpoint the endpoint
 * @return the request
 */
protected Request send(Request request, Endpoint outEndpoint) {
	// use the specified message type
	request.setType(this.type);

	if (blockwise!=0) {
		request.getOptions().setBlock2(new BlockOption(BlockOption.size2Szx(this.blockwise), false, 0));
	}
	
	outEndpoint.sendRequest(request);
	return request;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:19,代码来源:CoapClient.java


示例10: CoapServer

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Constructs a server with the specified configuration that listens to the
 * specified ports after method {@link #start()} is called.
 *
 * @param config the configuration, if <code>null</code> the configuration returned by
 * {@link NetworkConfig#getStandard()} is used.
 * @param ports the ports to bind to
 */
public CoapServer(NetworkConfig config, int... ports) {
	
	// global configuration that is passed down (can be observed for changes)
	if (config != null) {
		this.config = config;
	} else {
		this.config = NetworkConfig.getStandard();
	}
	
	// resources
	this.root = createRoot();
	this.deliverer = new ServerMessageDeliverer(root);
	
	CoapResource well_known = new CoapResource(".well-known");
	well_known.setVisible(false);
	well_known.add(new DiscoveryResource(root));
	root.add(well_known);
	
	// endpoints
	this.endpoints = new ArrayList<Endpoint>();
	// sets the central thread pool for the protocol stage over all endpoints
	this.executor = Executors.newScheduledThreadPool( config.getInt(NetworkConfig.Keys.PROTOCOL_STAGE_THREAD_COUNT) );
	// create endpoint for each port
	for (int port:ports)
		addEndpoint(new CoapEndpoint(port, this.config));
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:35,代码来源:CoapServer.java


示例11: setExecutor

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
public void setExecutor(ScheduledExecutorService executor) {
	
	if (this.executor!=null) this.executor.shutdown();
	
	this.executor = executor;
	for (Endpoint ep:endpoints)
		ep.setExecutor(executor);
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:9,代码来源:CoapServer.java


示例12: start

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Starts the server by starting all endpoints this server is assigned to.
 * Each endpoint binds to its port. If no endpoint is assigned to the
 * server, an endpoint is started on the port defined in the config.
 */
@Override
public void start() {
	
	LOGGER.info("Starting server");
	
	if (endpoints.isEmpty()) {
		// servers should bind to the configured port (while clients should use an ephemeral port through the default endpoint)
		int port = config.getInt(NetworkConfig.Keys.COAP_PORT);
		LOGGER.info("No endpoints have been defined for server, setting up server endpoint on default port " + port);
		addEndpoint(new CoapEndpoint(port, this.config));
	}
	
	int started = 0;
	for (Endpoint ep:endpoints) {
		try {
			ep.start();
			// only reached on success
			++started;
		} catch (IOException e) {
			LOGGER.severe(e.getMessage() + " at " + ep.getAddress());
		}
	}
	if (started==0) {
		throw new IllegalStateException("None of the server endpoints could be started");
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:32,代码来源:CoapServer.java


示例13: stop

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Stops the server, i.e., unbinds it from all ports. Frees as much system
 * resources as possible to still be able to be re-started with the previous binds.
 */
@Override
public void stop() {
	LOGGER.info("Stopping server");
	for (Endpoint ep:endpoints)
		ep.stop();
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:11,代码来源:CoapServer.java


示例14: destroy

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Destroys the server, i.e., unbinds from all ports and frees all system resources.
 */
@Override
public void destroy() {
	LOGGER.info("Destroy server");
	for (Endpoint ep:endpoints)
		ep.destroy();
	executor.shutdown(); // cannot be started again
	try {
		boolean succ = executor.awaitTermination(5, TimeUnit.SECONDS);
		if (!succ)
			LOGGER.warning("Server executor did not shutdown in time");
	} catch (InterruptedException e) {
		LOGGER.log(Level.WARNING, "Exception while terminating server executor", e);
	}
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:18,代码来源:CoapServer.java


示例15: getEndpoint

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Returns the endpoint with a specific port.
 * @param port the port
 * @return the endpoint 
 */
@Override
public Endpoint getEndpoint(int port) {
	Endpoint endpoint = null;

	for (Endpoint ep : endpoints) {
		if (ep.getAddress().getPort() == port) {
			endpoint = ep;
		}
	}
	return endpoint;
}
 
开发者ID:iotoasis,项目名称:SI,代码行数:17,代码来源:CoapServer.java


示例16: CaliforniumLwM2mRequestSender

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * @param endpoints the CoAP endpoints to use for sending requests
 * @param observationService the service for keeping track of observed resources
 * @param modelProvider provides the supported objects definitions
 */
public CaliforniumLwM2mRequestSender(Set<Endpoint> endpoints, ObservationServiceImpl observationService,
        LwM2mModelProvider modelProvider, LwM2mNodeEncoder encoder, LwM2mNodeDecoder decoder) {
    Validate.notNull(endpoints);
    Validate.notNull(observationService);
    Validate.notNull(modelProvider);
    this.observationService = observationService;
    this.endpoints = endpoints;
    this.modelProvider = modelProvider;
    this.encoder = encoder;
    this.decoder = decoder;
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:17,代码来源:CaliforniumLwM2mRequestSender.java


示例17: send

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
@Override
public <T extends LwM2mResponse> T send(final Registration destination, final DownlinkRequest<T> request,
        long timeout) throws InterruptedException {

    // Retrieve the objects definition
    final LwM2mModel model = modelProvider.getObjectModel(destination);

    // Create the CoAP request from LwM2m request
    CoapRequestBuilder coapRequestBuilder = new CoapRequestBuilder(destination.getIdentity(), destination.getRootPath(),
            destination.getId(), destination.getEndpoint(), model, encoder);
    request.accept(coapRequestBuilder);
    final Request coapRequest = coapRequestBuilder.getRequest();

    // Send CoAP request synchronously
    SyncRequestObserver<T> syncMessageObserver = new SyncRequestObserver<T>(coapRequest, timeout) {
        @Override
        public T buildResponse(Response coapResponse) {
            // Build LwM2m response
            LwM2mResponseBuilder<T> lwm2mResponseBuilder = new LwM2mResponseBuilder<>(coapRequest, coapResponse,
                    destination, model, observationService, decoder);
            request.accept(lwm2mResponseBuilder);
            return lwm2mResponseBuilder.getResponse();
        }
    };
    coapRequest.addMessageObserver(syncMessageObserver);

    // Store pending request to cancel it on de-registration
    addPendingRequest(destination.getId(), coapRequest);

    // Send CoAP request asynchronously
    Endpoint endpoint = getEndpointForClient(destination);
    endpoint.sendRequest(coapRequest);

    // Wait for response, then return it
    return syncMessageObserver.waitForResponse();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:37,代码来源:CaliforniumLwM2mRequestSender.java


示例18: getEndpointForClient

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Gets the CoAP endpoint that should be used to communicate with a given client.
 *
 * @param registration the client
 * @return the CoAP endpoint bound to the same network address and port that the client connected to during
 *         registration. If no such CoAP endpoint is available, the first CoAP endpoint from the list of registered
 *         endpoints is returned
 */
private Endpoint getEndpointForClient(Registration registration) {
    for (Endpoint ep : endpoints) {
        InetSocketAddress endpointAddress = ep.getAddress();
        if (endpointAddress.equals(registration.getRegistrationEndpointAddress())) {
            return ep;
        }
    }
    throw new IllegalStateException(
            "can't find the client endpoint for address : " + registration.getRegistrationEndpointAddress());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:19,代码来源:CaliforniumLwM2mRequestSender.java


示例19: register_with_additional_attributes

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
@Test
public void register_with_additional_attributes() throws InterruptedException {
    // Check registration
    helper.assertClientNotRegisterered();

    // HACK to be able to send a Registration request with additional attributes
    LeshanClient lclient = helper.client;
    lclient.getCoapServer().start();
    Endpoint secureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getSecuredAddress());
    Endpoint nonSecureEndpoint = lclient.getCoapServer().getEndpoint(lclient.getUnsecuredAddress());
    CaliforniumLwM2mRequestSender sender = new CaliforniumLwM2mRequestSender(secureEndpoint, nonSecureEndpoint);

    // Create Request with additional attributes
    Map<String, String> additionalAttributes = new HashMap<>();
    additionalAttributes.put("key1", "value1");
    additionalAttributes.put("imei", "2136872368");
    Link[] objectLinks = Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes());
    RegisterRequest registerRequest = new RegisterRequest(helper.getCurrentEndpoint(), null, null, null, null,
            objectLinks, additionalAttributes);

    // Send request
    RegisterResponse resp = sender.send(helper.server.getUnsecuredAddress(), false, registerRequest, 5000l);
    helper.waitForRegistration(1);

    // Check we are registered with the expected attributes
    helper.assertClientRegisterered();
    assertNotNull(helper.last_registration);
    assertEquals(additionalAttributes, helper.last_registration.getAdditionalRegistrationAttributes());
    assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>".getBytes()),
            helper.getCurrentRegistration().getObjectLinks());

    sender.send(helper.server.getUnsecuredAddress(), false, new DeregisterRequest(resp.getRegistrationID()), 5000l);
    lclient.getCoapServer().stop();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:35,代码来源:RegistrationTest.java


示例20: createClient

import org.eclipse.californium.core.network.Endpoint; //导入依赖的package包/类
/**
 * Create a CoapClient associated with the current server
 *
 * @return
 */
private CoapClient createClient() {
	CoapClient client = new CoapClient();
	List<Endpoint> endpoints = server.getEndpoints();
	client.setExecutor(server.getRoot().getExecutor());
	if (!endpoints.isEmpty()) {
		Endpoint ep = endpoints.get(0);
		client.setEndpoint(ep);
	}
	return client;
}
 
开发者ID:mkovatsc,项目名称:iot-semantics,代码行数:16,代码来源:ResourceDirectorySynchronizationService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OnTurnBasedMatchUpdateReceivedListener类代码示例发布时间:2022-05-23
下一篇:
Java JPacket类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap