Examples of ObservationCancelledEvent


Examples of de.uniluebeck.itm.ncoap.communication.events.client.ObservationCancelledEvent

                    executor.schedule(new Runnable() {
                        @Override
                        public void run() {
                            Token token = coapMessage.getToken();
                            ObservationCancelledEvent event = new ObservationCancelledEvent(remoteEndpoint, token,
                                    ObservationCancelledEvent.Reason.ACTIVE_CANCELLATION_BY_CLIENT);
                            Channels.write(ctx.getChannel(), event);
                        }
                    }, 0, TimeUnit.SECONDS);
                }

                //CoAP ping
                else if(coapMessage.getMessageTypeName() == MessageType.Name.CON &&
                        coapMessage.getMessageCodeName() == MessageCode.Name.EMPTY){

                    Token emptyToken = new Token(new byte[0]);
                    if(this.clientCallbacks.contains(remoteEndpoint, emptyToken)){
                        String description = "Empty token for remote endpoint " + remoteEndpoint + " not available.";
                        clientCallback.processMiscellaneousError(description);
                        return;
                    }

                    else{
                        coapMessage.setToken(emptyToken);
                    }
                }

                else{
                    //Prepare CoAP request, the response reception and then send the CoAP request
                    Token token = tokenFactory.getNextToken(remoteEndpoint);

                    if(token == null){
                        String description = "No token available for remote endpoint " + remoteEndpoint + ".";
                        clientCallback.processMiscellaneousError(description);
                        return;
                    }

                    else{
                        coapMessage.setToken(token);
                    }
                }

                //Add the response callback to wait for the inbound response
                addResponseCallback(remoteEndpoint, coapMessage.getToken(), clientCallback);

                //Send the request
                sendCoapMessage(ctx, me.getFuture(), coapMessage, remoteEndpoint);
                return;
            }
            catch (Exception ex) {
                log.error("This should never happen!", ex);
                removeClientCallback(remoteEndpoint, coapMessage.getToken());
            }
        }


//        else if (me.getMessage() instanceof ApplicationShutdownEvent){
//            this.clientCallbacks.clear();
//        }


        else if(me.getMessage() instanceof ObservationCancelledEvent){
            ObservationCancelledEvent message = (ObservationCancelledEvent) me.getMessage();

            if(removeClientCallback(message.getRemoteEndpoint(), message.getToken()) == null){
                log.error("Could not stop observation (remote endpoints: {}, token: {})! No callback found!",
                        message.getRemoteEndpoint(), message.getToken());
            }
        }

        ctx.sendDownstream(me);
View Full Code Here

Examples of de.uniluebeck.itm.ncoap.communication.events.client.ObservationCancelledEvent

            }

            //ask the callback if the observation is to be continued
            else if(!clientCallback.continueObservation()){
                //Send internal message to stop the observation
                ObservationCancelledEvent event = new ObservationCancelledEvent(remoteEndpoint, token,
                        ObservationCancelledEvent.Reason.LAZY_CANCELLATION_BY_CLIENT);
                log.debug("Send observation cancelation event!");
                Channels.write(ctx.getChannel(), event);
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.