/* (non-Javadoc)
  * @see org.eclipse.californium.core.network.Endpoint#destroy()
  */
 @Override
 public synchronized void destroy() {
   LOGGER.log(Level.INFO, "Destroying endpoint at address " + getAddress());
   if (started) stop();
   connector.destroy();
   for (EndpointObserver obs : observers) obs.destroyed(this);
 }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.network.Endpoint#stop()
  */
 @Override
 public synchronized void stop() {
   if (!started) {
     LOGGER.log(Level.INFO, "Endpoint at " + getAddress() + " is already stopped");
   } else {
     LOGGER.log(Level.INFO, "Stopping endpoint at address " + getAddress());
     started = false;
     connector.stop();
     matcher.stop();
     for (EndpointObserver obs : observers) obs.stopped(this);
     matcher.clear();
   }
 }
  /* (non-Javadoc)
   * @see org.eclipse.californium.core.network.Endpoint#start()
   */
  @Override
  public synchronized void start() throws IOException {
    if (started) {
      LOGGER.log(Level.FINE, "Endpoint at " + getAddress().toString() + " is already started");
      return;
    }

    if (!this.coapstack.hasDeliverer()) this.coapstack.setDeliverer(new ClientMessageDeliverer());

    if (this.executor == null) {
      LOGGER.config(
          "Endpoint "
              + toString()
              + " requires an executor to start. Using default single-threaded daemon executor.");

      final ScheduledExecutorService executor =
          Executors.newSingleThreadScheduledExecutor(new Utils.DaemonThreadFactory());
      setExecutor(executor);
      addObserver(
          new EndpointObserver() {
            public void started(Endpoint endpoint) {}

            public void stopped(Endpoint endpoint) {}

            public void destroyed(Endpoint endpoint) {
              executor.shutdown();
            }
          });
    }

    try {
      LOGGER.log(Level.INFO, "Starting endpoint at " + getAddress());

      started = true;
      matcher.start();
      connector.start();
      for (EndpointObserver obs : observers) obs.started(this);
      startExecutor();
    } catch (IOException e) {
      // free partially acquired resources
      stop();
      throw e;
    }
  }
 /* (non-Javadoc)
  * @see org.eclipse.californium.core.network.Endpoint#getAddress()
  */
 @Override
 public InetSocketAddress getAddress() {
   return connector.getAddress();
 }