You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Niko_K <ni...@krismer.de> on 2009/10/27 10:37:13 UTC

LogService start order - can start be forced before othér bundles?

I am trying to use the Apache Felix LogService in my own bundles to provide
logging to several bundles (i use a jdk-log delegation to make logging as
simple as possible)

However, the LogService-Bundle itself seems to start after my bundles.
Although logging is possible after some time when using a service listener,
the very first logging messages get lost since the service is not registered
at this time (they are not really lost, but they are logged by the jdk
rather than by the service).

So if i try to get a LogService ServiceReference at the beginning of the
start method in my bundles i get a null object. After some time the service
listener notices the registration of the LogService and everything works...

My question now is:
[b]Is it possible to force the LogService bundle to start before my own
bundles, so that logging is possible from the very first beginning?[/b]

Regards,
Niko
-- 
View this message in context: http://www.nabble.com/LogService-start-order---can-start-be-forced-before-oth%C3%A9r-bundles--tp26074675p26074675.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: LogService start order - can start be forced before othér bundles?

Posted by Guo Du <mr...@gmail.com>.
On Tue, Oct 27, 2009 at 2:47 PM, Niko_K <ni...@krismer.de> wrote:
>
>
> Richard S. Hall wrote:
>>
>> You have two options:
>>
>>    1. You can modify your other bundles to wait until a log service is
>>       available before continuing, thus they won't try to use it before
>>       it appears.
>>    2. You can install the log service into start level 1 and all your
>>       other bundles into start level 2 (look in the spec for start
>> levels).
>>
>> Approach 2 is simpler, but your bundles are more fragile and difficult
>> to reuse in other projects.
>>
>> -> richard
>>
>
> I guess that using a comination of both approaches is the best way to go.
> I am planning to use the log service only if it is available. Otherwise the
> jdk log will be available.

spring-osgi-extender implemented the mandatory dependencies
management. It could solve you problem only if you using spring-osgi
:)
http://static.springsource.org/osgi/docs/2.0.0.M1/reference/html/bnd-app-ctx.html#bnd-app-ctx:app-creation:mandatory-deps

-Guo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: LogService start order - can start be forced before othér bundles?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 10/27/09 10:47, Niko_K wrote:
>
> Richard S. Hall wrote:
>    
>> You have two options:
>>
>>     1. You can modify your other bundles to wait until a log service is
>>        available before continuing, thus they won't try to use it before
>>        it appears.
>>     2. You can install the log service into start level 1 and all your
>>        other bundles into start level 2 (look in the spec for start
>> levels).
>>
>> Approach 2 is simpler, but your bundles are more fragile and difficult
>> to reuse in other projects.
>>
>> ->  richard
>>
>>      
> I guess that using a comination of both approaches is the best way to go.
> I am planning to use the log service only if it is available. Otherwise the
> jdk log will be available.
>
> Is there a tutorial somewhere around the web that shows how to work with
> startlevels.
> How do i have to modify my startup class to work with startlevel:
> <code>
> 		Map<String, String>  configMap = new HashMap<String, String>();
> 		configMap.put(AutoProcessor.AUTO_DEPLOY_DIR_VALUE, "bundle");
> 		configMap.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
> AutoProcessor.AUTO_DEPLOY_UNINSTALL_VALUE + ',' +
> 																AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE + ',' +
> 																AutoProcessor.AUTO_DEPLOY_START_VALUE + ',' +
> 																AutoProcessor.AUTO_DEPLOY_UPDATE_VALUE);
>    

The auto-deploy directory does not support start levels. If you want 
start levels, you will have to use the Felix framework launcher 
auto-start property or install the bundles programmatically.

-> richard

> 		configMap.put(Constants.FRAMEWORK_STORAGE, "cache");
> 		configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN,
> Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
> 		configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
> "javax.swing.plaf," +
> 																"javax.swing.plaf.metal," +
> 																"com.sun.java.swing.plaf.gtk," +
> 																"com.sun.java.swing.plaf.motif," +
> 																"com.sun.java.swing.plaf.nimbus," +
> 																"com.sun.java.swing.plaf.windows");
>
> 		try {
> 			framework = getFrameworkFactory().newFramework(configMap);
> 			framework.init();
> 			AutoProcessor.process(configMap, framework.getBundleContext());
> 			framework.start();
> 			framework.waitForStop(0);
> 			System.exit(0);
> 		} catch (Exception ex) {
> 			System.err.println("Could not create framework: " + ex);
> 			System.exit(-1);
> 		}
> </code>
>
> Greetings.
> Niko
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: LogService start order - can start be forced before othér bundles?

Posted by Niko_K <ni...@krismer.de>.

Richard S. Hall wrote:
> 
> You have two options:
> 
>    1. You can modify your other bundles to wait until a log service is
>       available before continuing, thus they won't try to use it before
>       it appears.
>    2. You can install the log service into start level 1 and all your
>       other bundles into start level 2 (look in the spec for start
> levels).
> 
> Approach 2 is simpler, but your bundles are more fragile and difficult 
> to reuse in other projects.
> 
> -> richard
> 

I guess that using a comination of both approaches is the best way to go.
I am planning to use the log service only if it is available. Otherwise the
jdk log will be available.

Is there a tutorial somewhere around the web that shows how to work with
startlevels.
How do i have to modify my startup class to work with startlevel:
<code>
		Map<String, String> configMap = new HashMap<String, String>();
		configMap.put(AutoProcessor.AUTO_DEPLOY_DIR_VALUE, "bundle");
		configMap.put(AutoProcessor.AUTO_DEPLOY_ACTION_PROPERY,
AutoProcessor.AUTO_DEPLOY_UNINSTALL_VALUE + ',' +
																AutoProcessor.AUTO_DEPLOY_INSTALL_VALUE + ',' +
																AutoProcessor.AUTO_DEPLOY_START_VALUE + ',' +
																AutoProcessor.AUTO_DEPLOY_UPDATE_VALUE);
		configMap.put(Constants.FRAMEWORK_STORAGE, "cache");
		configMap.put(Constants.FRAMEWORK_STORAGE_CLEAN,
Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
		configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"javax.swing.plaf," +
																"javax.swing.plaf.metal," +
																"com.sun.java.swing.plaf.gtk," +
																"com.sun.java.swing.plaf.motif," +
																"com.sun.java.swing.plaf.nimbus," + 
																"com.sun.java.swing.plaf.windows");

		try {
			framework = getFrameworkFactory().newFramework(configMap);
			framework.init();
			AutoProcessor.process(configMap, framework.getBundleContext());
			framework.start();
			framework.waitForStop(0);
			System.exit(0);
		} catch (Exception ex) {
			System.err.println("Could not create framework: " + ex);
			System.exit(-1);
		}
</code>

Greetings.
Niko
-- 
View this message in context: http://www.nabble.com/LogService-start-order---can-start-be-forced-before-oth%C3%A9r-bundles--tp26074675p26079047.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: LogService start order - can start be forced before othér bundles?

Posted by "Richard S. Hall" <he...@ungoverned.org>.
You have two options:

   1. You can modify your other bundles to wait until a log service is
      available before continuing, thus they won't try to use it before
      it appears.
   2. You can install the log service into start level 1 and all your
      other bundles into start level 2 (look in the spec for start levels).

Approach 2 is simpler, but your bundles are more fragile and difficult 
to reuse in other projects.

-> richard

On 10/27/09 5:37, Niko_K wrote:
> I am trying to use the Apache Felix LogService in my own bundles to provide
> logging to several bundles (i use a jdk-log delegation to make logging as
> simple as possible)
>
> However, the LogService-Bundle itself seems to start after my bundles.
> Although logging is possible after some time when using a service listener,
> the very first logging messages get lost since the service is not registered
> at this time (they are not really lost, but they are logged by the jdk
> rather than by the service).
>
> So if i try to get a LogService ServiceReference at the beginning of the
> start method in my bundles i get a null object. After some time the service
> listener notices the registration of the LogService and everything works...
>
> My question now is:
> [b]Is it possible to force the LogService bundle to start before my own
> bundles, so that logging is possible from the very first beginning?[/b]
>
> Regards,
> Niko
>    

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org