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


Java ObserveResponse类代码示例

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


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

示例1: observe

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
public ObserveResponse observe(int resourceid) {
    // Perform a read by default
    ReadResponse readResponse = this.read(resourceid);
    return new ObserveResponse(readResponse.getCode(), readResponse.getContent(), null, null,
            readResponse.getErrorMessage());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:8,代码来源:BaseInstanceEnabler.java

示例2: onResponse

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
public void onResponse(Observation observation, Registration registration, ObserveResponse response) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Received notification from [{}] containing value [{}]", observation.getPath(),
                response.getContent().toString());
    }

    if (registration != null) {
        String data = new StringBuffer("{\"ep\":\"").append(registration.getEndpoint()).append("\",\"res\":\"")
                .append(observation.getPath().toString()).append("\",\"val\":")
                .append(gson.toJson(response.getContent()))
                .append("}").toString();

        sendEvent(EVENT_NOTIFICATION, data, registration.getEndpoint());
    }
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:17,代码来源:EventServlet.java

示例3: observe

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
public synchronized ObserveResponse observe(ServerIdentity identity, ObserveRequest request) {
    LwM2mPath path = request.getPath();

    // observe is not supported for bootstrap
    if (identity.isLwm2mBootstrapServer())
        return ObserveResponse.methodNotAllowed();

    if (!identity.isSystem()) {
        // observe or read of the security object is forbidden
        if (id == LwM2mId.SECURITY)
            return ObserveResponse.notFound();

        // check if the resource is readable.
        if (path.isResource()) {
            ResourceModel resourceModel = objectModel.resources.get(path.getResourceId());
            if (resourceModel != null && !resourceModel.operations.isReadable())
                return ObserveResponse.methodNotAllowed();
        }
    }
    return doObserve(identity, request);
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:23,代码来源:BaseObjectEnabler.java

示例4: doObserve

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
protected ObserveResponse doObserve(final ServerIdentity identity, final ObserveRequest request) {
    final LwM2mPath path = request.getPath();

    // Manage Object case
    if (path.isObject()) {
        List<LwM2mObjectInstance> lwM2mObjectInstances = new ArrayList<>();
        for (Entry<Integer, LwM2mInstanceEnabler> entry : instances.entrySet()) {
            lwM2mObjectInstances.add(getLwM2mObjectInstance(entry.getKey(), entry.getValue(), identity, true));
        }
        return ObserveResponse.success(new LwM2mObject(getId(), lwM2mObjectInstances));
    }

    // Manage Instance case
    final LwM2mInstanceEnabler instance = instances.get(path.getObjectInstanceId());
    if (instance == null)
        return ObserveResponse.notFound();

    if (path.getResourceId() == null) {
        return ObserveResponse
                .success(getLwM2mObjectInstance(path.getObjectInstanceId(), instance, identity, true));
    }

    // Manage Resource case
    return instance.observe(path.getResourceId());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:27,代码来源:ObjectEnabler.java

示例5: registered

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
     public void registered(Registration registration) {
  
System.out.println(registration.getEndpoint() + " is registrered!");
System.out.println("hava resource: ");

for(int i = 0; i < registration.getObjectLinks().length; i ++){
	System.out.println("\t" + registration.getObjectLinks()[i].getUrl());
	if(!registration.getObjectLinks()[i].getUrl().equals("/")){
		String lwm2mpath = "/"+ registration.getEndpoint() + registration.getObjectLinks()[i].getUrl();
		
		try {
			if (registration != null) {
				ContentFormat contentFormat = ContentFormat.fromName("JSON");
				// create & process request
		        for(int j = 0; j < ConfLoader.uploads.size();j++){
		        	 String path = ConfLoader.uploads.get(j).getLwM2MPath();
		        	 if(path.startsWith(lwm2mpath)){
		        		 
			        		 String observationpath = path.substring(registration.getEndpoint().length() + 1, path.length());
			                 
			        		 ObserveRequest request = new ObserveRequest(contentFormat, observationpath);
			                 ObserveResponse cResponse = lwServer.send(registration, request, 5000);
			                 
			                 emitValue(path, cResponse.getContent().toString());
			                 
			                 System.out.println("Observer Response: " + cResponse.toString());
		                 }
		            }     
		       } 
	     } catch (RuntimeException | InterruptedException e){
	    	 
	     }
	}
}
     }
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:37,代码来源:SimpleLwm2mServer.java

示例6: onResponse

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
public void onResponse(Observation observation, Registration registration, ObserveResponse response) {
    if (registration != null) {      
        System.out.println("Receive a new sensing data from " + observation.getPath() + " [" + response.getContent() + "]");
        
        String lwm2mpath = "/"+ registration.getEndpoint() + observation.getPath();
        
        emitValue(lwm2mpath, response.getContent().toString());
    }
}
 
开发者ID:IoTKETI,项目名称:IPE-LWM2M,代码行数:11,代码来源:SimpleLwm2mServer.java

示例7: createObserveResponse

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
private ObserveResponse createObserveResponse(Observation observation, LwM2mModel model, Response coapResponse) {
    // CHANGED response is supported for backward compatibility with old spec.
    if (coapResponse.getCode() != CoAP.ResponseCode.CHANGED
            && coapResponse.getCode() != CoAP.ResponseCode.CONTENT) {
        throw new InvalidResponseException("Unexpected response code [%s] for %s", coapResponse.getCode(),
                observation);
    }

    // get content format
    ContentFormat contentFormat = null;
    if (coapResponse.getOptions().hasContentFormat()) {
        contentFormat = ContentFormat.fromCode(coapResponse.getOptions().getContentFormat());
    }

    // decode response
    try {
        List<TimestampedLwM2mNode> timestampedNodes = decoder.decodeTimestampedData(coapResponse.getPayload(),
                contentFormat, observation.getPath(), model);

        // create lwm2m response
        if (timestampedNodes.size() == 1 && !timestampedNodes.get(0).isTimestamped()) {
            return new ObserveResponse(toLwM2mResponseCode(coapResponse.getCode()),
                    timestampedNodes.get(0).getNode(), null, observation, null, coapResponse);
        } else {
            return new ObserveResponse(toLwM2mResponseCode(coapResponse.getCode()), null, timestampedNodes,
                    observation, null, coapResponse);
        }
    } catch (CodecException e) {
        if (LOG.isDebugEnabled()) {
            byte[] payload = coapResponse.getPayload() == null ? new byte[0] : coapResponse.getPayload();
            LOG.debug(String.format("Unable to decode notification payload [%s] of observation [%s] ",
                    Hex.encodeHexString(payload), observation), e);
        }
        throw new InvalidResponseException(e, "Unable to decode notification payload  of observation [%s] ",
                observation);
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:38,代码来源:ObservationServiceImpl.java

示例8: can_observe_resource

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Test
public void can_observe_resource() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(),
            new ObserveRequest(3, 0, 15));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0/15", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertEquals(LwM2mSingleResource.newStringResource(15, "Europe/Paris"), listener.getResponse().getContent());
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:34,代码来源:ObserveTest.java

示例9: can_observe_instance

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Test
public void can_observe_instance() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3, 0));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertTrue(listener.getResponse().getContent() instanceof LwM2mObjectInstance);
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));

    // try to read the object instance for comparing
    ReadResponse readResp = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0));

    assertEquals(readResp.getContent(), listener.getResponse().getContent());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:38,代码来源:ObserveTest.java

示例10: can_observe_object

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Test
public void can_observe_object() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(), new ObserveRequest(3));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // write device timezone
    LwM2mResponse writeResponse = helper.server.send(helper.getCurrentRegistration(),
            new WriteRequest(3, 0, 15, "Europe/Paris"));

    // verify result
    listener.waitForNotification(2000);
    assertEquals(ResponseCode.CHANGED, writeResponse.getCode());
    assertTrue(listener.receivedNotify().get());
    assertTrue(listener.getResponse().getContent() instanceof LwM2mObject);
    assertNotNull(listener.getResponse().getCoapResponse());
    assertThat(listener.getResponse().getCoapResponse(), is(instanceOf(Response.class)));

    // try to read the object for comparing
    ReadResponse readResp = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3));

    assertEquals(readResp.getContent(), listener.getResponse().getContent());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:38,代码来源:ObserveTest.java

示例11: can_handle_error_on_notification

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Test
public void can_handle_error_on_notification() throws InterruptedException {
    TestObservationListener listener = new TestObservationListener();
    helper.server.getObservationService().addListener(listener);

    // observe device timezone
    ObserveResponse observeResponse = helper.server.send(helper.getCurrentRegistration(),
            new ObserveRequest(3, 0, 15));
    assertEquals(ResponseCode.CONTENT, observeResponse.getCode());
    assertNotNull(observeResponse.getCoapResponse());
    assertThat(observeResponse.getCoapResponse(), is(instanceOf(Response.class)));

    // an observation response should have been sent
    Observation observation = observeResponse.getObservation();
    assertEquals("/3/0/15", observation.getPath().toString());
    assertEquals(helper.getCurrentRegistration().getId(), observation.getRegistrationId());
    Set<Observation> observations = helper.server.getObservationService()
            .getObservations(helper.getCurrentRegistration());
    assertTrue("We should have only on observation", observations.size() == 1);
    assertTrue("New observation is not there", observations.contains(observation));

    // *** HACK send a notification with unsupported content format *** //
    byte[] payload = LwM2mNodeJsonEncoder.encode(LwM2mSingleResource.newStringResource(15, "Paris"),
            new LwM2mPath("/3/0/15"), new LwM2mModel(helper.createObjectModels()),
            new DefaultLwM2mValueConverter());
    Response firstCoapResponse = (Response) observeResponse.getCoapResponse();
    sendNotification(getConnector(helper.client), payload, firstCoapResponse, 666); // 666 is not a supported //
                                                                                    // contentFormat.
    // *** Hack End *** //

    // verify result
    listener.waitForNotification(2000);
    assertTrue(listener.receivedNotify().get());
    assertNotNull(listener.getError());
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:36,代码来源:ObserveTest.java

示例12: onResponse

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
@Override
public void onResponse(Observation observation, Registration registration, ObserveResponse response) {
    receivedNotify.set(true);
    this.response = response;
    this.error = null;
    latch.countDown();
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:8,代码来源:ObserveTest.java

示例13: jSerialize

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
public static JsonObject jSerialize(LwM2mResponse r) {
    final JsonObject o = Json.object();
    o.add("code", r.getCode().toString());

    if (r.isFailure()) {
        o.add("errorMessage", r.getErrorMessage());
        return o;
    }

    if (r instanceof ReadResponse) {
        o.add("kind", "read");
        o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent()));
    } else if (r instanceof ObserveResponse) {
        o.add("kind", "observe");
        o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent()));
    } else if (r instanceof DiscoverResponse) {
        o.add("kind", "discover");
        o.add("objectLinks", Link.serialize(((DiscoverResponse) r).getObjectLinks()));
    } else if (r instanceof DeleteResponse) {
        o.add("kind", "delete");
    } else if (r instanceof ExecuteResponse) {
        o.add("kind", "execute");
    } else if (r instanceof WriteResponse) {
        o.add("kind", "write");
    } else if (r instanceof WriteAttributesResponse) {
        o.add("kind", "writeAttributes");
    } else if (r instanceof CreateResponse) {
        o.add("kind", "create");
        o.add("location", ((CreateResponse) r).getLocation());
    }

    return o;
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:34,代码来源:ResponseSerDes.java

示例14: sendNotification

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
private void sendNotification(String ticket, LwM2mNode value) {
    try (Jedis j = pool.getResource()) {
        JsonObject m = Json.object();
        m.add("ticket", ticket);
        m.add("rep", ResponseSerDes.jSerialize(ObserveResponse.success(value)));
        j.publish(RESPONSE_CHANNEL, m.toString());
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:9,代码来源:RedisRequestResponseHandler.java

示例15: sendResponse

import org.eclipse.leshan.core.response.ObserveResponse; //导入依赖的package包/类
private void sendResponse(String ticket, LwM2mResponse response) {
    if (response instanceof ObserveResponse) {
        Observation observation = ((ObserveResponse) response).getObservation();
        observatioIdToTicket.put(new KeyId(observation.getId()), ticket);
    }
    try (Jedis j = pool.getResource()) {
        JsonObject m = Json.object();
        m.add("ticket", ticket);
        m.add("rep", ResponseSerDes.jSerialize(response));
        j.publish(RESPONSE_CHANNEL, m.toString());
    }
}
 
开发者ID:eclipse,项目名称:leshan,代码行数:13,代码来源:RedisRequestResponseHandler.java


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