You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by jo...@exceter.com on 2011/06/24 20:23:40 UTC

BundleListener and System.out

I have the following bundle activator which implements both  
FrameworkListener and BundleListener,


import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;

public class ListenerActivator implements BundleActivator,  
FrameworkListener, BundleListener
{
   private int invoked = 0;

   public void start(BundleContext bundleContext) throws Exception
   {
     // Add the listeners
     System.out.println("Adding listeners");
     bundleContext.addFrameworkListener(this);
     bundleContext.addBundleListener(this);
   }

   public void stop(BundleContext bundleContext) throws Exception
   {
     // Remove the listeners
     System.out.println("Removing listeners " + invoked);
     bundleContext.removeFrameworkListener(this);
     bundleContext.removeBundleListener(this);
   }

   public void frameworkEvent(FrameworkEvent event)
   {
     System.out.println("\tFrameworkEvent(type=" + event.getType() +
     ",bundle=" + event.getBundle() +
     ",source=" + event.getSource() +
     ",throwable=" + event.getThrowable() + ")");
     invoked++;
   }

   public void bundleChanged(BundleEvent event)
   {
     System.out.println("\tBundleEvent(type=" + event.getType() +
     ",bundle=" + event.getBundle() +
     ",source=" + event.getSource() + ")");
     invoked++;
   }
}

However, when I run this in karaf the System.out.println calls within  
the start/stop methods work but the ones within frameworkEvent and  
bundleChanged do not. I know they are being invoked because the stop  
method displays an integer value larger than zero. Why isn't  
System.out working?

-John


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


Re: BundleListener and System.out

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 6/27/11 13:29, john.dunlap@exceter.com wrote:
> I'm not sure why but when I use SynchronousBundleListener instead of 
> BundleListener the output starts appearing in the console.

Still sounds like potential redirection per thread, since synchronous 
events would happen on a different thread. You may want to ask this 
question on the Karaf list if you can't get an answer here.

-> richard

>
> Quoting john.dunlap@exceter.com:
>
>>
>> I modified my class to this but I am still not seeing anything on the
>> console. I would have expected this to account for System.out being
>> redirected.
>>
>> public class ListenerActivator implements BundleActivator,
>> FrameworkListener, BundleListener
>> {
>>   private int invoked = 0;
>>
>>   private PrintStream out;
>>
>>   public void start(BundleContext bundleContext) throws Exception
>>   {
>>     out = System.out;
>>
>>     // Add the listeners
>>     out.println("Adding listeners...");
>>     bundleContext.addFrameworkListener(this);
>>     bundleContext.addBundleListener(this);
>>   }
>>
>>   public void stop(BundleContext bundleContext) throws Exception
>>   {
>>     // Remove the listeners
>>     out.println("Removing listeners... " + invoked);
>>     bundleContext.removeFrameworkListener(this);
>>     bundleContext.removeBundleListener(this);
>>   }
>>
>>   public void frameworkEvent(FrameworkEvent event)
>>   {
>>     out.println("\tFrameworkEvent(type=" + event.getType() +
>>     ",bundle=" + event.getBundle() +
>>     ",source=" + event.getSource() +
>>     ",throwable=" + event.getThrowable() + ")");
>>     invoked++;
>>   }
>>
>>   public void bundleChanged(BundleEvent event)
>>   {
>>     out.println("\tBundleEvent(type=" + event.getType() +
>>     ",bundle=" + event.getBundle() +
>>     ",source=" + event.getSource() + ")");
>>     invoked++;
>>   }
>> }
>>
>>
>> Quoting john.dunlap@exceter.com:
>>
>>> Pax Logging is installed in karaf by default so that's definitely
>>> possible. Thanks!
>>>
>>> Quoting "Richard S. Hall" <he...@ungoverned.org>:
>>>
>>>> On 6/24/11 20:23, john.dunlap@exceter.com wrote:
>>>>> I have the following bundle activator which implements both    
>>>>> FrameworkListener and BundleListener,
>>>>>
>>>>>
>>>>> import org.osgi.framework.BundleActivator;
>>>>> import org.osgi.framework.BundleContext;
>>>>> import org.osgi.framework.BundleEvent;
>>>>> import org.osgi.framework.BundleListener;
>>>>> import org.osgi.framework.FrameworkEvent;
>>>>> import org.osgi.framework.FrameworkListener;
>>>>>
>>>>> public class ListenerActivator implements BundleActivator,    
>>>>> FrameworkListener, BundleListener
>>>>> {
>>>>> private int invoked = 0;
>>>>>
>>>>> public void start(BundleContext bundleContext) throws Exception
>>>>> {
>>>>>  // Add the listeners
>>>>>  System.out.println("Adding listeners");
>>>>>  bundleContext.addFrameworkListener(this);
>>>>>  bundleContext.addBundleListener(this);
>>>>> }
>>>>>
>>>>> public void stop(BundleContext bundleContext) throws Exception
>>>>> {
>>>>>  // Remove the listeners
>>>>>  System.out.println("Removing listeners " + invoked);
>>>>>  bundleContext.removeFrameworkListener(this);
>>>>>  bundleContext.removeBundleListener(this);
>>>>> }
>>>>>
>>>>> public void frameworkEvent(FrameworkEvent event)
>>>>> {
>>>>>  System.out.println("\tFrameworkEvent(type=" + event.getType() +
>>>>>  ",bundle=" + event.getBundle() +
>>>>>  ",source=" + event.getSource() +
>>>>>  ",throwable=" + event.getThrowable() + ")");
>>>>>  invoked++;
>>>>> }
>>>>>
>>>>> public void bundleChanged(BundleEvent event)
>>>>> {
>>>>>  System.out.println("\tBundleEvent(type=" + event.getType() +
>>>>>  ",bundle=" + event.getBundle() +
>>>>>  ",source=" + event.getSource() + ")");
>>>>>  invoked++;
>>>>> }
>>>>> }
>>>>>
>>>>> However, when I run this in karaf the System.out.println calls    
>>>>> within the start/stop methods work but the ones within    
>>>>> frameworkEvent and bundleChanged do not. I know they are being    
>>>>> invoked because the stop method displays an integer value larger  
>>>>>   than zero. Why isn't System.out working?
>>>>
>>>> I'm guessing someone is grabbing stdout and setting it to something
>>>> else, perhaps for logging.
>>>>
>>>> -> richard
>>>>
>>>>>
>>>>> -John
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

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


Re: BundleListener and System.out

Posted by jo...@exceter.com.
I'm not sure why but when I use SynchronousBundleListener instead of  
BundleListener the output starts appearing in the console.

Quoting john.dunlap@exceter.com:

>
> I modified my class to this but I am still not seeing anything on the
> console. I would have expected this to account for System.out being
> redirected.
>
> public class ListenerActivator implements BundleActivator,
> FrameworkListener, BundleListener
> {
>   private int invoked = 0;
>
>   private PrintStream out;
>
>   public void start(BundleContext bundleContext) throws Exception
>   {
>     out = System.out;
>
>     // Add the listeners
>     out.println("Adding listeners...");
>     bundleContext.addFrameworkListener(this);
>     bundleContext.addBundleListener(this);
>   }
>
>   public void stop(BundleContext bundleContext) throws Exception
>   {
>     // Remove the listeners
>     out.println("Removing listeners... " + invoked);
>     bundleContext.removeFrameworkListener(this);
>     bundleContext.removeBundleListener(this);
>   }
>
>   public void frameworkEvent(FrameworkEvent event)
>   {
>     out.println("\tFrameworkEvent(type=" + event.getType() +
>     ",bundle=" + event.getBundle() +
>     ",source=" + event.getSource() +
>     ",throwable=" + event.getThrowable() + ")");
>     invoked++;
>   }
>
>   public void bundleChanged(BundleEvent event)
>   {
>     out.println("\tBundleEvent(type=" + event.getType() +
>     ",bundle=" + event.getBundle() +
>     ",source=" + event.getSource() + ")");
>     invoked++;
>   }
> }
>
>
> Quoting john.dunlap@exceter.com:
>
>> Pax Logging is installed in karaf by default so that's definitely
>> possible. Thanks!
>>
>> Quoting "Richard S. Hall" <he...@ungoverned.org>:
>>
>>> On 6/24/11 20:23, john.dunlap@exceter.com wrote:
>>>> I have the following bundle activator which implements both     
>>>> FrameworkListener and BundleListener,
>>>>
>>>>
>>>> import org.osgi.framework.BundleActivator;
>>>> import org.osgi.framework.BundleContext;
>>>> import org.osgi.framework.BundleEvent;
>>>> import org.osgi.framework.BundleListener;
>>>> import org.osgi.framework.FrameworkEvent;
>>>> import org.osgi.framework.FrameworkListener;
>>>>
>>>> public class ListenerActivator implements BundleActivator,     
>>>> FrameworkListener, BundleListener
>>>> {
>>>> private int invoked = 0;
>>>>
>>>> public void start(BundleContext bundleContext) throws Exception
>>>> {
>>>>  // Add the listeners
>>>>  System.out.println("Adding listeners");
>>>>  bundleContext.addFrameworkListener(this);
>>>>  bundleContext.addBundleListener(this);
>>>> }
>>>>
>>>> public void stop(BundleContext bundleContext) throws Exception
>>>> {
>>>>  // Remove the listeners
>>>>  System.out.println("Removing listeners " + invoked);
>>>>  bundleContext.removeFrameworkListener(this);
>>>>  bundleContext.removeBundleListener(this);
>>>> }
>>>>
>>>> public void frameworkEvent(FrameworkEvent event)
>>>> {
>>>>  System.out.println("\tFrameworkEvent(type=" + event.getType() +
>>>>  ",bundle=" + event.getBundle() +
>>>>  ",source=" + event.getSource() +
>>>>  ",throwable=" + event.getThrowable() + ")");
>>>>  invoked++;
>>>> }
>>>>
>>>> public void bundleChanged(BundleEvent event)
>>>> {
>>>>  System.out.println("\tBundleEvent(type=" + event.getType() +
>>>>  ",bundle=" + event.getBundle() +
>>>>  ",source=" + event.getSource() + ")");
>>>>  invoked++;
>>>> }
>>>> }
>>>>
>>>> However, when I run this in karaf the System.out.println calls     
>>>> within the start/stop methods work but the ones within     
>>>> frameworkEvent and bundleChanged do not. I know they are being     
>>>> invoked because the stop method displays an integer value larger   
>>>>   than zero. Why isn't System.out working?
>>>
>>> I'm guessing someone is grabbing stdout and setting it to something
>>> else, perhaps for logging.
>>>
>>> -> richard
>>>
>>>>
>>>> -John
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>>> For additional commands, e-mail: users-help@felix.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org




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


Re: BundleListener and System.out

Posted by jo...@exceter.com.
I modified my class to this but I am still not seeing anything on the  
console. I would have expected this to account for System.out being  
redirected.

public class ListenerActivator implements BundleActivator,  
FrameworkListener, BundleListener
{
   private int invoked = 0;

   private PrintStream out;

   public void start(BundleContext bundleContext) throws Exception
   {
     out = System.out;

     // Add the listeners
     out.println("Adding listeners...");
     bundleContext.addFrameworkListener(this);
     bundleContext.addBundleListener(this);
   }

   public void stop(BundleContext bundleContext) throws Exception
   {
     // Remove the listeners
     out.println("Removing listeners... " + invoked);
     bundleContext.removeFrameworkListener(this);
     bundleContext.removeBundleListener(this);
   }

   public void frameworkEvent(FrameworkEvent event)
   {
     out.println("\tFrameworkEvent(type=" + event.getType() +
     ",bundle=" + event.getBundle() +
     ",source=" + event.getSource() +
     ",throwable=" + event.getThrowable() + ")");
     invoked++;
   }

   public void bundleChanged(BundleEvent event)
   {
     out.println("\tBundleEvent(type=" + event.getType() +
     ",bundle=" + event.getBundle() +
     ",source=" + event.getSource() + ")");
     invoked++;
   }
}


Quoting john.dunlap@exceter.com:

> Pax Logging is installed in karaf by default so that's definitely
> possible. Thanks!
>
> Quoting "Richard S. Hall" <he...@ungoverned.org>:
>
>> On 6/24/11 20:23, john.dunlap@exceter.com wrote:
>>> I have the following bundle activator which implements both    
>>> FrameworkListener and BundleListener,
>>>
>>>
>>> import org.osgi.framework.BundleActivator;
>>> import org.osgi.framework.BundleContext;
>>> import org.osgi.framework.BundleEvent;
>>> import org.osgi.framework.BundleListener;
>>> import org.osgi.framework.FrameworkEvent;
>>> import org.osgi.framework.FrameworkListener;
>>>
>>> public class ListenerActivator implements BundleActivator,    
>>> FrameworkListener, BundleListener
>>> {
>>> private int invoked = 0;
>>>
>>> public void start(BundleContext bundleContext) throws Exception
>>> {
>>>   // Add the listeners
>>>   System.out.println("Adding listeners");
>>>   bundleContext.addFrameworkListener(this);
>>>   bundleContext.addBundleListener(this);
>>> }
>>>
>>> public void stop(BundleContext bundleContext) throws Exception
>>> {
>>>   // Remove the listeners
>>>   System.out.println("Removing listeners " + invoked);
>>>   bundleContext.removeFrameworkListener(this);
>>>   bundleContext.removeBundleListener(this);
>>> }
>>>
>>> public void frameworkEvent(FrameworkEvent event)
>>> {
>>>   System.out.println("\tFrameworkEvent(type=" + event.getType() +
>>>   ",bundle=" + event.getBundle() +
>>>   ",source=" + event.getSource() +
>>>   ",throwable=" + event.getThrowable() + ")");
>>>   invoked++;
>>> }
>>>
>>> public void bundleChanged(BundleEvent event)
>>> {
>>>   System.out.println("\tBundleEvent(type=" + event.getType() +
>>>   ",bundle=" + event.getBundle() +
>>>   ",source=" + event.getSource() + ")");
>>>   invoked++;
>>> }
>>> }
>>>
>>> However, when I run this in karaf the System.out.println calls    
>>> within the start/stop methods work but the ones within    
>>> frameworkEvent and bundleChanged do not. I know they are being    
>>> invoked because the stop method displays an integer value larger    
>>> than zero. Why isn't System.out working?
>>
>> I'm guessing someone is grabbing stdout and setting it to something
>> else, perhaps for logging.
>>
>> -> richard
>>
>>>
>>> -John
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>>> For additional commands, e-mail: users-help@felix.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org




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


Re: BundleListener and System.out

Posted by jo...@exceter.com.
Pax Logging is installed in karaf by default so that's definitely  
possible. Thanks!

Quoting "Richard S. Hall" <he...@ungoverned.org>:

> On 6/24/11 20:23, john.dunlap@exceter.com wrote:
>> I have the following bundle activator which implements both   
>> FrameworkListener and BundleListener,
>>
>>
>> import org.osgi.framework.BundleActivator;
>> import org.osgi.framework.BundleContext;
>> import org.osgi.framework.BundleEvent;
>> import org.osgi.framework.BundleListener;
>> import org.osgi.framework.FrameworkEvent;
>> import org.osgi.framework.FrameworkListener;
>>
>> public class ListenerActivator implements BundleActivator,   
>> FrameworkListener, BundleListener
>> {
>>  private int invoked = 0;
>>
>>  public void start(BundleContext bundleContext) throws Exception
>>  {
>>    // Add the listeners
>>    System.out.println("Adding listeners");
>>    bundleContext.addFrameworkListener(this);
>>    bundleContext.addBundleListener(this);
>>  }
>>
>>  public void stop(BundleContext bundleContext) throws Exception
>>  {
>>    // Remove the listeners
>>    System.out.println("Removing listeners " + invoked);
>>    bundleContext.removeFrameworkListener(this);
>>    bundleContext.removeBundleListener(this);
>>  }
>>
>>  public void frameworkEvent(FrameworkEvent event)
>>  {
>>    System.out.println("\tFrameworkEvent(type=" + event.getType() +
>>    ",bundle=" + event.getBundle() +
>>    ",source=" + event.getSource() +
>>    ",throwable=" + event.getThrowable() + ")");
>>    invoked++;
>>  }
>>
>>  public void bundleChanged(BundleEvent event)
>>  {
>>    System.out.println("\tBundleEvent(type=" + event.getType() +
>>    ",bundle=" + event.getBundle() +
>>    ",source=" + event.getSource() + ")");
>>    invoked++;
>>  }
>> }
>>
>> However, when I run this in karaf the System.out.println calls   
>> within the start/stop methods work but the ones within   
>> frameworkEvent and bundleChanged do not. I know they are being   
>> invoked because the stop method displays an integer value larger   
>> than zero. Why isn't System.out working?
>
> I'm guessing someone is grabbing stdout and setting it to something
> else, perhaps for logging.
>
> -> richard
>
>>
>> -John
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org




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


Re: BundleListener and System.out

Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 6/24/11 20:23, john.dunlap@exceter.com wrote:
> I have the following bundle activator which implements both 
> FrameworkListener and BundleListener,
>
>
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
> import org.osgi.framework.BundleEvent;
> import org.osgi.framework.BundleListener;
> import org.osgi.framework.FrameworkEvent;
> import org.osgi.framework.FrameworkListener;
>
> public class ListenerActivator implements BundleActivator, 
> FrameworkListener, BundleListener
> {
>   private int invoked = 0;
>
>   public void start(BundleContext bundleContext) throws Exception
>   {
>     // Add the listeners
>     System.out.println("Adding listeners");
>     bundleContext.addFrameworkListener(this);
>     bundleContext.addBundleListener(this);
>   }
>
>   public void stop(BundleContext bundleContext) throws Exception
>   {
>     // Remove the listeners
>     System.out.println("Removing listeners " + invoked);
>     bundleContext.removeFrameworkListener(this);
>     bundleContext.removeBundleListener(this);
>   }
>
>   public void frameworkEvent(FrameworkEvent event)
>   {
>     System.out.println("\tFrameworkEvent(type=" + event.getType() +
>     ",bundle=" + event.getBundle() +
>     ",source=" + event.getSource() +
>     ",throwable=" + event.getThrowable() + ")");
>     invoked++;
>   }
>
>   public void bundleChanged(BundleEvent event)
>   {
>     System.out.println("\tBundleEvent(type=" + event.getType() +
>     ",bundle=" + event.getBundle() +
>     ",source=" + event.getSource() + ")");
>     invoked++;
>   }
> }
>
> However, when I run this in karaf the System.out.println calls within 
> the start/stop methods work but the ones within frameworkEvent and 
> bundleChanged do not. I know they are being invoked because the stop 
> method displays an integer value larger than zero. Why isn't 
> System.out working?

I'm guessing someone is grabbing stdout and setting it to something 
else, perhaps for logging.

-> richard

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

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