You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by 蓝天白云 <do...@gmail.com> on 2009/05/04 19:09:27 UTC

Problems with developing Tapestry 5 on osgi environment

Hi,

I'm developing Tapestry 5 base on osgi environment recently and it's almost
done at this time but 3 problems:

First, I have to show you how tapestry-osgi works in shortly:
tapestry-osgi is suported by 2 bundles:
*org.extwind.osgi.http.filter*  - Register FilterService as osgi service,
like HttpService
*org.extwind.osgi.tapestry*  -  Register TapestryFilter by FilterService,
and register ComponentService as osgi service.


The ComponentService is used to register/unregister a root package of module
(bundle) into Tapestry dynamically
public interface ComponentService {
    public void registerPackage(String packageName);
    public void unregisterPackage(String packageName);
}

Override ComponentClassResolver to finding page/component/minix class and
mapping page/component/minix name, to locate class and resources, need a
ComponentLocator
public interface ComponentLocatorRegistry {
    public void register(String packageName, ComponentLocator pageLocator);
    public void unregister(String packageName);
}
Every component bundles which would like to register a package into tapestry
will be associated to a ComponentLocator, so tapestry can find resources
from them.

 The global AppModule is located in bundle org.extwind.osgi.tapestry to
override services.

*1. case-insensitive*

As we know, java is a case-sensitive world,, I really can't make sense why
tapestry built with case-insensitive.
But it's not a major problem with osgi, I just per-loading tapestry's
componets at the time when bundle startup, like following:

*TapestryConstants.java*
static final Collection<String> TAPESTRY_PAGES_CLASSES = new
ArrayList<String>(3);
 static final Collection<String> TAPESTRY_COMPONENTS_CLASSES = new
ArrayList<String>(44);
 static final Collection<String> TAPESTRY_MIXINS_CLASSES = new
ArrayList<String>(70);

 static final String ROOT_PACKAGE = "org.apache.tapestry5.corelib";
 static final String PATH_PREFIX= "core";
 static {
  // Pages
  TAPESTRY_PAGES_CLASSES.add("org.apache.tapestry5.corelib.pages.ExceptionReport");
   .............. and more

*2. controlledPackageNames*

I can't remove packages from controlledPackageNames when component bundles
stop until get any supported method from ComponentInstantiatorSource such
like

 void removePackage(String packageName);

*3. Service binding*
 This is a major problem with osgi.
I just researched how tapestry's service binding, if any chance to provide a
way to add modules in Registry or something else like following:

addModules(Collection<ModuleDef> moduleDefs, ...)

Registry can be hold in *org.extwind.osgi.tapestry* to accept modules
registered by components bundles dynamically, through override
TapestryFilter.init(Registry) like following:

FilterService filterService = (FilterService) context.getService(reference);
Dictionary<String, String> dic = new Hashtable<String, String>();
dic.put(InternalConstants.TAPESTRY_APP_PACKAGE_PARAM,
"org.extwind.osgi.tapestry");
dic.put("filter-name", "app");

filterService.registerFilter("/*", new TapestryFilter() {
    protected void init(Registry registry) throws ServletException {
     ComponentLocatorRegistry componentLocatorRegistry =
AppModule.getPageLocatorRegistry();
     pageServiceRegistration =
context.registerService(ComponentService.class.getName(),
       new ComponentServiceListener(componentLocatorRegistry, registry),
null);
    }
   }, dic, null);
   ...... and more

Get source code of tapestry-osgi from
http://extwind.googlecode.com/svn/trunk/Tapestry-OSGi/

And also Tomcat-OSGi is on programming if any interestings to you,
documents are all in Chinese and translating to English.


Appreciates for any suggestions.


Regards,

Donf Yang
------------------------------------------------------------------------------
To be surprised,to wonder,is to begin to understand.

Re: Problems with developing Tapestry 5 on osgi environment

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 04 May 2009 22:59:59 -0300, 蓝天白云 <do...@gmail.com>  
escreveu:

> When tapestry handling a http request to "/start" on the first time,
> TapestryComponentClassResolver.resolvePageNameToClassName() will try
> to locate the class of logic name "com.foo.pages.start", and mapping the
> classname to logic name if found, then any request to "/start" in further
> will be done in tapestry's way.
>
> so, the problem is, how I locate a class by the case-insensitive logic  
> name? (if the request path is "/thisiSmyPage", truely this is fine in
> traditional way)

What about doing what Tapestry does: use a CaseInsensitiveMap<Class> to  
hold pairs of (class name, Class instance) ?.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org


Re: Problems with developing Tapestry 5 on osgi environment

Posted by 蓝天白云 <do...@gmail.com>.
ComponentLocator is used to find a class corresponding to some
page/component/mixin.
public interface ComponentLocator {
 public static final int LOCATE_PAGE = 1;
 public static final int LOCATE_COMPONENT = 2;
 public static final int LOCATE_MIXIN = 3;
 /**
  * Locate a class by logic name and locate type
  */
 public String locate(String logicName, int locateType);
 public boolean isClassExists(String className);
}

When tapestry handling a http request to "/start" on the first time,
TapestryComponentClassResolver.resolvePageNameToClassName() will try
to locate the class of logic name "com.foo.pages.start", and mapping the
classname to logic name if found, then any request to "/start" in further
will be done in tapestry's way.

so, the problem is, how I locate a class by the case-insensitive logic name
? (if the request path is "/thisiSmyPage", truely this is fine in
traditional way)


2009/5/5 Thiago H. de Paula Figueiredo <th...@gmail.com>

> Em Mon, 04 May 2009 14:09:27 -0300, 蓝天白云 <do...@gmail.com> escreveu:
>
> Hi,
>>
>
> Hi!
>
> I'm developing Tapestry 5 base on osgi environment recently
>>
>
> Nice! Could you share the code with use when it's done?
>
> and it's almost done at this time but 3 problems:
>>
> [snip]
>
>> *1. case-insensitive*
>>
>> As we know, java is a case-sensitive world,, I really can't make sense why
>> tapestry built with case-insensitive.
>>
>
> I'm not familiar with OSGi, but what's the problem here?
>
> *2. controlledPackageNames*
>>
>> I can't remove packages from controlledPackageNames when component bundles
>> stop until get any supported method from ComponentInstantiatorSource such
>> like
>>
>>  void removePackage(String packageName);
>>
>
> Components (and pages and mixins) are added through Tapestry IoC, which
> loads all modules at registry startup time. After that, you can't add nor
> remove modules (including components, pages and mixins).
>
> *3. Service binding*
>>  This is a major problem with osgi.
>> I just researched how tapestry's service binding, if any chance to provide
>> a way to add modules in Registry or something else like following:
>>
>> addModules(Collection<ModuleDef> moduleDefs, ...)
>>
>
> You cannot add modules after the Registry is created, but you can add them
> before, using RegistryBuilder directly. Or, in the case of the
> TapestryFilter, using TapestryAppInitializer. Reading your code, I've found
> this line in
> http://extwind.googlecode.com/svn/trunk/Tapestry-OSGi/org.extwind.osgi.tapestry/src/org/extwind/osgi/tapestry/internal/proxy/ProxyTapestryFilter.java
> :
>
> TapestryAppInitializer appInitializer = new
> TapestryAppInitializer(provider, filterName, "servlet");
>
> After this line, you can call appInitializer.addModules(Class... modules)
> to add any Tapestry-IoC module you need.
>
> I hope I gave you some good hints. :)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 

Regards,

Donf Yang
------------------------------------------------------------------------------
To be surprised,to wonder,is to begin to understand.

Re: Problems with developing Tapestry 5 on osgi environment

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 04 May 2009 14:09:27 -0300, 蓝天白云 <do...@gmail.com>  
escreveu:

> Hi,

Hi!

> I'm developing Tapestry 5 base on osgi environment recently

Nice! Could you share the code with use when it's done?

> and it's almost done at this time but 3 problems:
[snip]
> *1. case-insensitive*
>
> As we know, java is a case-sensitive world,, I really can't make sense  
> why tapestry built with case-insensitive.

I'm not familiar with OSGi, but what's the problem here?

> *2. controlledPackageNames*
>
> I can't remove packages from controlledPackageNames when component  
> bundles
> stop until get any supported method from ComponentInstantiatorSource such
> like
>
>  void removePackage(String packageName);

Components (and pages and mixins) are added through Tapestry IoC, which  
loads all modules at registry startup time. After that, you can't add nor  
remove modules (including components, pages and mixins).

> *3. Service binding*
>  This is a major problem with osgi.
> I just researched how tapestry's service binding, if any chance to  
> provide a way to add modules in Registry or something else like  
> following:
>
> addModules(Collection<ModuleDef> moduleDefs, ...)

You cannot add modules after the Registry is created, but you can add them  
before, using RegistryBuilder directly. Or, in the case of the  
TapestryFilter, using TapestryAppInitializer. Reading your code, I've  
found this line in  
http://extwind.googlecode.com/svn/trunk/Tapestry-OSGi/org.extwind.osgi.tapestry/src/org/extwind/osgi/tapestry/internal/proxy/ProxyTapestryFilter.java:

TapestryAppInitializer appInitializer = new  
TapestryAppInitializer(provider, filterName, "servlet");

After this line, you can call appInitializer.addModules(Class... modules)  
to add any Tapestry-IoC module you need.

I hope I gave you some good hints. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org