Chenqiulin created FELIX-4756:
---------------------------------

             Summary: Throw Invalid BundleContext when getAllServiceReferences()
                 Key: FELIX-4756
                 URL: https://issues.apache.org/jira/browse/FELIX-4756
             Project: Felix
          Issue Type: Bug
          Components: Framework
    Affects Versions: framework-4.0.1
         Environment: Centos 6.0  JDK 6
            Reporter: Chenqiulin


I registService like this:
public class ManagerActivator implements BundleActivator {


        private ServiceRegistration serviceRegistration;

        // 运行服务
        private ServiceRegistration serviceRegistrationRuntime;

        public void start(BundleContext context) throws Exception {

                Dictionary props = new Hashtable();
                // service.pid
                String symbolicName = (String) context.getBundle().getHeaders()
                                .get("Bundle-SymbolicName");
                props.put("service.pid", symbolicName);
                props.put(Constant.COMMANDNAME, "manager");

                serviceRegistrationRuntime = context.registerService(
                                AgentAction.class.getName(), new 
ManagerAction(context), props);
                logger.info("manager regist success.");         
        }
}

and I get the service like this:

public Response handle(Message message) {
                ServiceReference[] serviceRefs = null;
                Response result = null;
                try {
                        String mess = message.getContent().toString();
                        logger.debug(mess);
                        Map map = JsonUtil.toBean(mess, Map.class);
                        serviceRefs = context.getAllServiceReferences(
                                        AgentAction.class.getName(), "(" + 
Constant.COMMANDNAME
                                                        + "=manager)");
                        if (serviceRefs.length == 0) {
                                throw new Exception(" has not Command service 
like this ");
                        }
                        if (serviceRefs.length > 1) {
                                throw new Exception("more than one Command 
service like this ");
                        }
                        AgentAction action = (AgentAction) context
                                        .getService(serviceRefs[0]);
                        // handle
                        result = action.handle(message);
                } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                }

                return result;
        }


But I always get Exception :
  (AgentMessageHandler.java:72) ERROR - ******.AgentMessageHandler  - Invalid 
BundleContext.
java.lang.IllegalStateException: Invalid BundleContext.
    at 
org.apache.felix.framework.BundleContextImpl.checkValidity(BundleContextImpl.java:514)
    at 
org.apache.felix.framework.BundleContextImpl.getAllServiceReferences(BundleContextImpl.java:411)
    at 
cn.tianya.amm.agent.service.AgentMessageHandler.handle(AgentMessageHandler.java:55)
    at 
cn.tianya.fw.mq.impl.activemq.FwMqListenService$MessageSyncHandlerAdapter.run(FwMqListenService.java:582)
    at 
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

Did I need to synchronized regist service?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to