You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by James D Carroll <ja...@verizon.net> on 2008/08/02 05:32:00 UTC

JVM Version

I haven't seen anything in the doc that says what version JVM Felix
requires.  Could someone enlighten me please?

Thanks,



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


Re: Is there any way to access OSGi service from non-OSGi client

Posted by 梁宏鑫 <hx...@gmail.com>.
Thank you very much. ;-)

2008/8/6 Clement Escoffier <cl...@gmail.com>

>
>
>
>
> -----Original Message-----
> From: honnix [mailto:hxliang1982@gmail.com]
> Sent: mardi 5 août 2008 16:32
> To: users@felix.apache.org
> Subject: Re: Is there any way to access OSGi service from non-OSGi client
>
>
>
> clement escoffier wrote:
>
> > Hi,
>
> >
>
> > Are you embedding Felix inside a host ? In this case, you can access the
>
> > bundle context by invoking the getBundleContext() method on the Felix
>
> > object. This returns the System-bundle bundle context. Be aware that
> Felix
>
> > need to be started first.
>
> >
>
> > Always if you're embedding Felix, you can use something like the
> following
>
> > methods (using reflection) to invoke OSGi services from your host:
>
> >  public Object invokeServiceOperation(ServiceReference ref, String
>
> > methodName, Class[] argTypes, Object[] args) {
>
> >         Object svc = context.getService(ref);
>
> >         try {
>
> >             Method method = svc.getClass().getMethod(methodName,
> argTypes);
>
> >             return method.invoke(svc, args);
>
> >         } catch (Exception e) {
>
> >             System.err.println("Cannot invoke the service operation " +
>
> > methodName + " : " + e.getMessage());
>
> >         }
>
> >         return null;
>
> >     }
>
> >
>
> >     public Object lookAndInvokeServiceOperation(String itf, String
> filter,
>
> > String methodName, Class[] argTypes, Object[] args) {
>
> >         ServiceReference[] refs = null;
>
> >         try {
>
> >             refs = context.getServiceReferences(itf, filter);
>
> >             if (refs == null) {
>
> >                 System.err.println("Service lookup failed - no matching
>
> > provider " + itf + " " + filter);
>
> >                 return null;
>
> >             }
>
> >         } catch (InvalidSyntaxException e1) {
>
> >             System.err.println("Service lookup failed - invalid filter "
> +
>
> > itf + " " + filter);
>
> >             return null;
>
> >         }
>
> >
>
> >         Object svc = context.getService(refs[0]);
>
> >         try {
>
> >             Method method = svc.getClass().getMethod(methodName,
> argTypes);
>
> >             return method.invoke(svc, args);
>
> >         } catch (InvocationTargetException e) {
>
> >             System.err.println("Cannot invoke the service operation " +
>
> > methodName + " : " + e.getTargetException());
>
> >             e.getTargetException().printStackTrace();
>
> >         } catch (Exception e) {
>
> >             System.err.println("Cannot invoke the service operation " +
>
> > methodName + " : " + e.getMessage());
>
> >         }
>
> >         return null;
>
> >     }
>
> >
>
> >
>
> > If you want to access OSGi services remotely, there is several way to
> expose
>
> > OSGi service to be accessible remotely. Some works were made around Web
>
> > Services (especially X-Fire). More recently, a work using Hessian sounds
>
> > interristing
> (http://java.dzone.com/articles/hessian-service-and-client-osg).
>
> >
>
> >
>
> > Regards,
>
> >
>
> > Clement
>
> >
>
> > 2008/8/5 honnix <hx...@gmail.com>
>
> >
>
> >
>
> >> Seems that there is some classloader problem.
>
> >>
>
> >> How can I access OSGi bundle context, and how can I access OSGi service
>
> >> from some non-OSGi client. I searched in Google, but have no hint yet. I
> can
>
> >> get that using reflection way, but is there any convenient way?
>
> >>
>
> >> Thank you all.
>
> >>
>
> >> ---------------------------------------------------------------------
>
> >> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>
> >> For additional commands, e-mail: users-help@felix.apache.org
>
> >>
>
> >>
>
> >>
>
> >
>
> >
>
> Hi Clement,
>
>
>
> Thank you very much for your reply.
>
>
>
> Seems that the best way to invoke service is using reflection, right?
>
> And consider this situation:
>
>
>
> class FelixWrapper
>
> {
>
>    private static Felix felix = new Felix(...);
>
>
>
>    public static Felix getFelix()
>
>    {
>
>       return felix;
>
>    }
>
>
>
>    ...
>
> }
>
>
>
>
>
> This wrapper is loaded by some classloader, so I have to use the same
>
> classloader to find FelixWrapper class, and use reflection to get Felix
>
> instance.
>
>
>
> Class clazz = theClassLoader.loadClass("com.honnix.osgi.FelixWrapper");
>
> Method method = clazz.getMethod("getFelix", ...);
>
> Object felix = method.invoke(null, ...);
>
>
>
> clazz = theClassLoader.loadClass("org.apache.felix.framework.Felix");
>
> Method method = clazz.getMethod("getBundleContext", ...);
>
> Object bundleContext = method.invoke(felix, ...);
>
>
>
> ... use reflection on bundleContext to get bundles, service references,
>
> services ...
>
>
>
> Am I right?
>
>
>
> Brs,
>
> Honnix
>
>
>
>
>
> Yes, it should work. Be care that if your service operations return
> "non-standard" objects, you must use reflection to interact with these
> objects too.
>
>
>
> Regards,
>
>
>
> Clement
>
>
>
> ---------------------------------------------------------------------
>
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>
> For additional commands, e-mail: users-help@felix.apache.org
>
>
>
>

RE: Is there any way to access OSGi service from non-OSGi client

Posted by Clement Escoffier <cl...@gmail.com>.
 

 

-----Original Message-----
From: honnix [mailto:hxliang1982@gmail.com] 
Sent: mardi 5 août 2008 16:32
To: users@felix.apache.org
Subject: Re: Is there any way to access OSGi service from non-OSGi client

 

clement escoffier wrote:

> Hi,

> 

> Are you embedding Felix inside a host ? In this case, you can access the

> bundle context by invoking the getBundleContext() method on the Felix

> object. This returns the System-bundle bundle context. Be aware that Felix

> need to be started first.

> 

> Always if you're embedding Felix, you can use something like the following

> methods (using reflection) to invoke OSGi services from your host:

>  public Object invokeServiceOperation(ServiceReference ref, String

> methodName, Class[] argTypes, Object[] args) {

>         Object svc = context.getService(ref);

>         try {

>             Method method = svc.getClass().getMethod(methodName,
argTypes);

>             return method.invoke(svc, args);

>         } catch (Exception e) {

>             System.err.println("Cannot invoke the service operation " +

> methodName + " : " + e.getMessage());

>         }

>         return null;

>     }

> 

>     public Object lookAndInvokeServiceOperation(String itf, String filter,

> String methodName, Class[] argTypes, Object[] args) {

>         ServiceReference[] refs = null;

>         try {

>             refs = context.getServiceReferences(itf, filter);

>             if (refs == null) {

>                 System.err.println("Service lookup failed - no matching

> provider " + itf + " " + filter);

>                 return null;

>             }

>         } catch (InvalidSyntaxException e1) {

>             System.err.println("Service lookup failed - invalid filter " +

> itf + " " + filter);

>             return null;

>         }

> 

>         Object svc = context.getService(refs[0]);

>         try {

>             Method method = svc.getClass().getMethod(methodName,
argTypes);

>             return method.invoke(svc, args);

>         } catch (InvocationTargetException e) {

>             System.err.println("Cannot invoke the service operation " +

> methodName + " : " + e.getTargetException());

>             e.getTargetException().printStackTrace();

>         } catch (Exception e) {

>             System.err.println("Cannot invoke the service operation " +

> methodName + " : " + e.getMessage());

>         }

>         return null;

>     }

> 

> 

> If you want to access OSGi services remotely, there is several way to
expose

> OSGi service to be accessible remotely. Some works were made around Web

> Services (especially X-Fire). More recently, a work using Hessian sounds

> interristing
(http://java.dzone.com/articles/hessian-service-and-client-osg).

> 

> 

> Regards,

> 

> Clement

> 

> 2008/8/5 honnix <hx...@gmail.com>

> 

>   

>> Seems that there is some classloader problem.

>> 

>> How can I access OSGi bundle context, and how can I access OSGi service

>> from some non-OSGi client. I searched in Google, but have no hint yet. I
can

>> get that using reflection way, but is there any convenient way?

>> 

>> Thank you all.

>> 

>> ---------------------------------------------------------------------

>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org

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

>> 

>> 

>>     

> 

>   

Hi Clement,

 

Thank you very much for your reply.

 

Seems that the best way to invoke service is using reflection, right? 

And consider this situation:

 

class FelixWrapper

{

    private static Felix felix = new Felix(...);

 

    public static Felix getFelix()

    {

       return felix;

    }

 

    ...

}

 

 

This wrapper is loaded by some classloader, so I have to use the same 

classloader to find FelixWrapper class, and use reflection to get Felix 

instance.

 

Class clazz = theClassLoader.loadClass("com.honnix.osgi.FelixWrapper");

Method method = clazz.getMethod("getFelix", ...);

Object felix = method.invoke(null, ...);

 

clazz = theClassLoader.loadClass("org.apache.felix.framework.Felix");

Method method = clazz.getMethod("getBundleContext", ...);

Object bundleContext = method.invoke(felix, ...);

 

... use reflection on bundleContext to get bundles, service references, 

services ...

 

Am I right?

 

Brs,

Honnix

 

 

Yes, it should work. Be care that if your service operations return
“non-standard” objects, you must use reflection to interact with these
objects too.

 

Regards,

 

Clement

 

---------------------------------------------------------------------

To unsubscribe, e-mail: users-unsubscribe@felix.apache.org

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

 


Re: Is there any way to access OSGi service from non-OSGi client

Posted by honnix <hx...@gmail.com>.
clement escoffier wrote:
> Hi,
>
> Are you embedding Felix inside a host ? In this case, you can access the
> bundle context by invoking the getBundleContext() method on the Felix
> object. This returns the System-bundle bundle context. Be aware that Felix
> need to be started first.
>
> Always if you're embedding Felix, you can use something like the following
> methods (using reflection) to invoke OSGi services from your host:
>  public Object invokeServiceOperation(ServiceReference ref, String
> methodName, Class[] argTypes, Object[] args) {
>         Object svc = context.getService(ref);
>         try {
>             Method method = svc.getClass().getMethod(methodName, argTypes);
>             return method.invoke(svc, args);
>         } catch (Exception e) {
>             System.err.println("Cannot invoke the service operation " +
> methodName + " : " + e.getMessage());
>         }
>         return null;
>     }
>
>     public Object lookAndInvokeServiceOperation(String itf, String filter,
> String methodName, Class[] argTypes, Object[] args) {
>         ServiceReference[] refs = null;
>         try {
>             refs = context.getServiceReferences(itf, filter);
>             if (refs == null) {
>                 System.err.println("Service lookup failed - no matching
> provider " + itf + " " + filter);
>                 return null;
>             }
>         } catch (InvalidSyntaxException e1) {
>             System.err.println("Service lookup failed - invalid filter " +
> itf + " " + filter);
>             return null;
>         }
>
>         Object svc = context.getService(refs[0]);
>         try {
>             Method method = svc.getClass().getMethod(methodName, argTypes);
>             return method.invoke(svc, args);
>         } catch (InvocationTargetException e) {
>             System.err.println("Cannot invoke the service operation " +
> methodName + " : " + e.getTargetException());
>             e.getTargetException().printStackTrace();
>         } catch (Exception e) {
>             System.err.println("Cannot invoke the service operation " +
> methodName + " : " + e.getMessage());
>         }
>         return null;
>     }
>
>
> If you want to access OSGi services remotely, there is several way to expose
> OSGi service to be accessible remotely. Some works were made around Web
> Services (especially X-Fire). More recently, a work using Hessian sounds
> interristing (http://java.dzone.com/articles/hessian-service-and-client-osg).
>
>
> Regards,
>
> Clement
>
> 2008/8/5 honnix <hx...@gmail.com>
>
>   
>> Seems that there is some classloader problem.
>>
>> How can I access OSGi bundle context, and how can I access OSGi service
>> from some non-OSGi client. I searched in Google, but have no hint yet. I can
>> get that using reflection way, but is there any convenient way?
>>
>> Thank you all.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>     
>
>   
Hi Clement,

Thank you very much for your reply.

Seems that the best way to invoke service is using reflection, right? 
And consider this situation:

class FelixWrapper
{
    private static Felix felix = new Felix(...);

    public static Felix getFelix()
    {
       return felix;
    }

    ...
}


This wrapper is loaded by some classloader, so I have to use the same 
classloader to find FelixWrapper class, and use reflection to get Felix 
instance.

Class clazz = theClassLoader.loadClass("com.honnix.osgi.FelixWrapper");
Method method = clazz.getMethod("getFelix", ...);
Object felix = method.invoke(null, ...);

clazz = theClassLoader.loadClass("org.apache.felix.framework.Felix");
Method method = clazz.getMethod("getBundleContext", ...);
Object bundleContext = method.invoke(felix, ...);

... use reflection on bundleContext to get bundles, service references, 
services ...

Am I right?

Brs,
Honnix

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


Re: Is there any way to access OSGi service from non-OSGi client

Posted by clement escoffier <cl...@gmail.com>.
Hi,

Are you embedding Felix inside a host ? In this case, you can access the
bundle context by invoking the getBundleContext() method on the Felix
object. This returns the System-bundle bundle context. Be aware that Felix
need to be started first.

Always if you're embedding Felix, you can use something like the following
methods (using reflection) to invoke OSGi services from your host:
 public Object invokeServiceOperation(ServiceReference ref, String
methodName, Class[] argTypes, Object[] args) {
        Object svc = context.getService(ref);
        try {
            Method method = svc.getClass().getMethod(methodName, argTypes);
            return method.invoke(svc, args);
        } catch (Exception e) {
            System.err.println("Cannot invoke the service operation " +
methodName + " : " + e.getMessage());
        }
        return null;
    }

    public Object lookAndInvokeServiceOperation(String itf, String filter,
String methodName, Class[] argTypes, Object[] args) {
        ServiceReference[] refs = null;
        try {
            refs = context.getServiceReferences(itf, filter);
            if (refs == null) {
                System.err.println("Service lookup failed - no matching
provider " + itf + " " + filter);
                return null;
            }
        } catch (InvalidSyntaxException e1) {
            System.err.println("Service lookup failed - invalid filter " +
itf + " " + filter);
            return null;
        }

        Object svc = context.getService(refs[0]);
        try {
            Method method = svc.getClass().getMethod(methodName, argTypes);
            return method.invoke(svc, args);
        } catch (InvocationTargetException e) {
            System.err.println("Cannot invoke the service operation " +
methodName + " : " + e.getTargetException());
            e.getTargetException().printStackTrace();
        } catch (Exception e) {
            System.err.println("Cannot invoke the service operation " +
methodName + " : " + e.getMessage());
        }
        return null;
    }


If you want to access OSGi services remotely, there is several way to expose
OSGi service to be accessible remotely. Some works were made around Web
Services (especially X-Fire). More recently, a work using Hessian sounds
interristing (http://java.dzone.com/articles/hessian-service-and-client-osg).


Regards,

Clement

2008/8/5 honnix <hx...@gmail.com>

> Seems that there is some classloader problem.
>
> How can I access OSGi bundle context, and how can I access OSGi service
> from some non-OSGi client. I searched in Google, but have no hint yet. I can
> get that using reflection way, but is there any convenient way?
>
> Thank you all.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>

Is there any way to access OSGi service from non-OSGi client

Posted by honnix <hx...@gmail.com>.
Seems that there is some classloader problem.

How can I access OSGi bundle context, and how can I access OSGi service 
from some non-OSGi client. I searched in Google, but have no hint yet. I 
can get that using reflection way, but is there any convenient way?

Thank you all.

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


Re: JVM Version

Posted by "Richard S. Hall" <he...@ungoverned.org>.
James D Carroll wrote:
> I had a thought.... 
> Does that have any effect on the JVM version that my bundles can use?
>   

No, you can write your bundles for any version of Java, but then you 
will obviously be forced to use that version to run your bundles.

-> richard

> Thanks,
>
>
> On Fri, 2008-08-01 at 23:42 -0400, Richard S. Hall wrote:
>   
>> James D Carroll wrote:
>>     
>>> I haven't seen anything in the doc that says what version JVM Felix
>>> requires.  Could someone enlighten me please?
>>>   
>>>       
>> We try to make sure that the Felix core framework works on a Java 1.3 
>> level...we definitely aren't using advanced Java features, so if you 
>> find that to be the case, please report it as a bug.
>>
>> -> richard
>>
>>     
>>> Thanks,
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: JVM Version

Posted by James D Carroll <ja...@verizon.net>.
I had a thought.... 
Does that have any effect on the JVM version that my bundles can use?

Thanks,


On Fri, 2008-08-01 at 23:42 -0400, Richard S. Hall wrote:
> James D Carroll wrote:
> > I haven't seen anything in the doc that says what version JVM Felix
> > requires.  Could someone enlighten me please?
> >   
> 
> We try to make sure that the Felix core framework works on a Java 1.3 
> level...we definitely aren't using advanced Java features, so if you 
> find that to be the case, please report it as a bug.
> 
> -> richard
> 
> > Thanks,
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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: JVM Version

Posted by "Richard S. Hall" <he...@ungoverned.org>.
James D Carroll wrote:
> Excellent! Thanks. 
>
>
> On Fri, 2008-08-01 at 23:42 -0400, Richard S. Hall wrote:
>   
>> James D Carroll wrote:
>>     
>>> I haven't seen anything in the doc that says what version JVM Felix
>>> requires.  Could someone enlighten me please?
>>>   
>>>       
>> We try to make sure that the Felix core framework works on a Java 1.3 
>> level...we definitely aren't using advanced Java features, so if you 
>> find that to be the case, please report it as a bug.
>>     

I guess that should have said, "so if you don't find that to be the case..."

You're welcome.

-> richard

>> -> richard
>>
>>     
>>> Thanks,
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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: JVM Version

Posted by James D Carroll <ja...@gmail.com>.
Excellent! Thanks. 


On Fri, 2008-08-01 at 23:42 -0400, Richard S. Hall wrote:
> James D Carroll wrote:
> > I haven't seen anything in the doc that says what version JVM Felix
> > requires.  Could someone enlighten me please?
> >   
> 
> We try to make sure that the Felix core framework works on a Java 1.3 
> level...we definitely aren't using advanced Java features, so if you 
> find that to be the case, please report it as a bug.
> 
> -> richard
> 
> > Thanks,
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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: JVM Version

Posted by "Richard S. Hall" <he...@ungoverned.org>.
James D Carroll wrote:
> I haven't seen anything in the doc that says what version JVM Felix
> requires.  Could someone enlighten me please?
>   

We try to make sure that the Felix core framework works on a Java 1.3 
level...we definitely aren't using advanced Java features, so if you 
find that to be the case, please report it as a bug.

-> richard

> Thanks,
>
>
>
> ---------------------------------------------------------------------
> 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