Package org.foo.managed.service

Source Code of org.foo.managed.service.ManagedServiceExample

package org.foo.managed.service;

import java.io.IOException;
import java.util.Dictionary;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;

public class ManagedServiceExample implements ManagedService {
  private EchoServer m_server = null;

  public synchronized void updated(Dictionary properties)
      throws ConfigurationException {
    if (m_server != null) {
      m_server.stop();
      m_server = null;
    }
    if (properties != null) {
      String portString = (String) properties.get("port");
      if (portString == null) {
        throw new ConfigurationException(null, "Property missing");
      }
      int port;
      try {
        port = Integer.parseInt(portString);
      } catch (NumberFormatException ex) {
        throw new ConfigurationException(null,
            "Not a valid port number");
      }
      try {
        m_server = new EchoServer(port);
        m_server.start();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
 
  synchronized void stop() {
    if (m_server != null) {
      m_server.stop();
      m_server = null;
    }
  }
}
TOP

Related Classes of org.foo.managed.service.ManagedServiceExample

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.