Hi Tyler,

I was wondering if there is a way to inject Elements at runtime. I
know that SiteBuilder can be utilized to create Elements, but once the
Site is instantiated is there a way to add new elements? The
requirements of my project require the addition of users, that will
have their own /username address, at runtime. Editing XML
configurations or rebooting the server are not viable options.

yes, you can do this. However, you can't just add one element. This, for the simple reason that RIFE site-structures can become very complex and a lot of declarations need to be taken into account that can alter the standalone behavior of an element. For example with sub- site or group inherits, global variables, global exits, ...

So, the basic principle is that when you need to modify the Site on- the-fly, you actually need to build a new one. If you look at the standard participant, you see that it actually almost does nothing: https://svn.rifers.org/rife/trunk/src/framework/com/uwyn/rife/rep/ participants/ParticipantSite.java

At each request, RIFE will obtain the Site instance from there, you can thus easily yourself update it with a new version when a user is added. There is also nothing that prevents your from creating one site, but mix and match in ways how to declare things. You can thus, for example, declare your main structure in XML and include a sub- site that is built dynamically using the pure-Java site builder approach: http://rifers.org/wiki/display/RIFE/Site+structure+and+element +declaration+without+XML

You will however have to let RIFE know how and when to access your dynamic sub-site. This is where the SiteProcessor and SiteProcessorFactory comes into play. Typically, you create a new static SiteProcessorFactory instance in a blocking participant in your repository:
public class CustomSiteProcessorParticipant extends BlockingParticipant
{
    public static final String SITE_IDENTIFIER = "mysite";
        
    {
new SiteProcessorFactory(SITE_IDENTIFIER, null, new MySiteProcessor());
    }
}

You can then in your XML declaration do:
<subsite id="SOMEID" file="mysite:someparam" urlprefix="/someurl"/>

You MySiteProcessor class then needs to implement the SiteProcessor interface, and you can use the SiteBuilder instance you receive in the processSite method any way you like to add declarations dynamically.

If you're interested, RIFE/Crud (https://svn.rifers.org/rife-crud/ trunk) is totally based on this.

I hope this was somewhat clear.

Best regards,

Geert

--
Geert Bevin                       Uwyn bvba
"Use what you need"               Avenue de Scailmont 34
http://www.uwyn.com               7170 Manage, Belgium
gbevin[remove] at uwyn dot com    Tel +32 64 84 80 03

PGP Fingerprint : 4E21 6399 CD9E A384 6619  719A C8F4 D40D 309F D6A9
Public PGP key  : available at servers pgp.mit.edu, wwwkeys.pgp.net


_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to