Hi!

Bill Petheram wrote:
> I'm OK up to System Resource now :-).
> 
> Could you define how a system resource is defined in jBoss?

You would typically make a JMX MBean that implements your resource
factory, and add it to jboss.conf so that it is created and managed as a
part of the jBoss server.

> As I understand it an EJB cannot use threads, sockets, files etc.
> However it seems that I can write a system resource that allows access
> to these things. This means to me that the container has to 'own, start,
> know about' the system resource and the EJB can only use it.

That would be correct. Although it would also be possible that the only
reference to the resource factory is through the EJB's. You could easily
make a JavaBean which is a system module that EJB's can use to access
files in the file system. This JavaBean could be pretty lightweight and
not necessarily have to be added as a "module" in the server. 

There are a vast number of possibilities here, so I can only give you a
gist of what is possible, not an exhaustive list of you can do.

> So if I write a system resource that conforms to the Connector
> Architecture I can use it in any EJB server. 

.. that supports the Connector Architecture. 

> If I write it as an MBean I
> could use it in jBoss.

If you make it an MBean then you can use it in any server that supports
JMX. But this is only for management of the resource. If your resource
doesn't really need this, then this is unnecessary. 

Here is the simplest example of a resource factory:
public MyResource
{
  public Properties getConfiguration()
    throws Exception
  {
    return (Properties)AccessController.doPrivileged(new
PrivilegedExceptionAction()
      {
        public Object run()
        {
          Properties cfg = new Properties();
         
cfg.load(getClass().getResourceAsStream("configuration.properties"));
          return cfg;
        }
      });
  }
}

It reads the file "configuration.properties" (which is not possible for
an EJB to do!!!) and puts the settings into a properties object which is
returned.
Note that it MUST use doPrivileged or it will fail since the EJB that is
calling it is not allowed to do file I/O.

Now our EJB code can get the configuration:
public String getSettingFoo()
  throws Exception
{
  return new MyResource().getConfiguration().getProperty("foo");
}

See? No MBean, no connector, but still it helps the EJB do things that
it is normally not allowed to do.

This topic has come up a lot of times on the EJB-INTEREST list so I
suggest that you check the archives of that list
(archives.java.sun.com).

/Rickard

-- 
Rickard �berg

@home: +46 13 177937
Email: [EMAIL PROTECTED]
http://www.telkel.com
http://www.jboss.org
http://www.dreambean.com


--
--------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Problems?:           [EMAIL PROTECTED]

Reply via email to