felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chenqiulin (JIRA)" <j...@apache.org>
Subject [jira] [Created] (FELIX-4752) getAllServiceReferences() Throw IllegalStateException: Invalid BundleContext
Date Tue, 06 Jan 2015 09:50:34 GMT
Chenqiulin created FELIX-4752:
---------------------------------

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


I register service like this:

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 Service 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);

			logger.info("begin to handle message " + map.get(MODULENAME));

			serviceRefs = context.getAllServiceReferences(
					AgentAction.class.getName(), "(" + Constant.COMMANDNAME
							+ "=" + map.get(MODULENAME) + ")");
			// serviceRefs = context.getAllServiceReferences(
			// AgentAction.class.getName(),null);
			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 the command
			result = action.handle(message);
		} catch (Exception e) {
			result = message.createResponse();
			result.setErrorMsg( e.getMessage());
			logger.error(e.getMessage(), e);
		}

       return result;
	}


the phenomenon is  I always catch the Exception(about 50%) like this:

ERROR - cn.tianya.amm.agent.service.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)




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

Mime
View raw message