Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Start own bundle in CDO Server
[CDO] Start own bundle in CDO Server [message #946554] Tue, 16 October 2012 09:36 Go to next message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
Hi,

I have a CDO server where I would like to add my own bundle. The bundle contains (CDO) code that reacts to a model change and does an operation (writes a file)).

It turns out to be really hard to start the "new" bundle together with the CDO server because:
- Either it will not start at all...
- Or it will start BEFORE CDO, which is not working since the bundle needs to create a CDO Session.

How can I do this properly?
Is there an CDO related osgi service or something that my bundle can depend on to make it start after the CDO server?

///Anders
Re: [CDO] Start own bundle in CDO Server [message #946629 is a reply to message #946554] Tue, 16 October 2012 11:01 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Am 16.10.2012 11:36, schrieb Anders Jönsson:
> Hi,
>
> I have a CDO server where I would like to add my own bundle. The bundle contains (CDO) code that reacts to a model
> change and does an operation (writes a file)).
>
> It turns out to be really hard to start the "new" bundle together with the CDO server because:
> - Either it will not start at all...
> - Or it will start BEFORE CDO, which is not working since the bundle needs to create a CDO Session.
>
> How can I do this properly?
> Is there an CDO related osgi service or something that my bundle can depend on to make it start after the CDO server?
You may want to implement and contribute an org.eclipse.emf.cdo.spi.server.IAppExtension ;-)

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Start own bundle in CDO Server [message #947606 is a reply to message #946629] Wed, 17 October 2012 08:29 Go to previous messageGo to next message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
>You may want to implement and contribute an org.eclipse.emf.cdo.spi.server.IAppExtension

Yes, it works perfect. Thanks a lot!

I use CDO client code in IAppExtension.start() to connect to the (same) server via tcp, start a session, open a view and listen to the model. Is this the preferred way to interact with the model or is there a more direct way to, for instance, open a view using CDO server code?


///Anders
Re: [CDO] Start own bundle in CDO Server [message #947618 is a reply to message #947606] Wed, 17 October 2012 08:43 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Am 17.10.2012 10:29, schrieb Anders Jönsson:
>> You may want to implement and contribute an org.eclipse.emf.cdo.spi.server.IAppExtension
>
> Yes, it works perfect. Thanks a lot!
Excellent ;-)

> I use CDO client code in IAppExtension.start() to connect to the (same) server via tcp,
Why not via JVM transport? That would be faster.

> start a session, open a view and listen to the model. Is this the preferred way to interact with the model
Yes.

> or is there a more direct way to, for instance, open a view using CDO server code?
You can open a ServerCDOView with these methods:

org.eclipse.emf.cdo.server.CDOServerUtil.openView(ISession, CDOBranchPoint, boolean, CDORevisionProvider)
org.eclipse.emf.cdo.server.CDOServerUtil.openView(ISession, CDOBranchPoint, boolean)
org.eclipse.emf.cdo.server.CDOServerUtil.openView(IView, boolean)
org.eclipse.emf.cdo.server.CDOServerUtil.openView(CommitContext, boolean)

But they have very limited capabilities, no write access, no invalidations. Just what's needed to traverse a state of
the model graph in terms of EObjects.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Start own bundle in CDO Server [message #947625 is a reply to message #947618] Wed, 17 October 2012 08:58 Go to previous messageGo to next message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
>> start a session, open a view and listen to the model. Is this the preferred way to interact with the model
>Yes.

Good to know. Thanks again!
///Anders
Re: [CDO] Start own bundle in CDO Server [message #1019369 is a reply to message #947625] Fri, 15 March 2013 14:57 Go to previous messageGo to next message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
Hi (again),


Is there a way to get notified when the CDO server has completed its startup (I thought IAppExtension would be it)?


In order to be able to run my own code in a cdo server application and specifically to start it in an orderly fashion i implemented an org.eclipse.emf.cdo.spi.server.IAppExtension.

In the IAppExtension I configure a CDOSession and start a CDOTransaction to the same server (which is currently beeing started).

It turns out there is no guarantee that the server is started, which may occasionally render an exception of type:
org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate TCPClientConnector[localhost:2,036]

It seems to be the "Net4j extension starting" part that may or may not have happened before the IAppExtensions are called.

///Anders

Re: [CDO] Start own bundle in CDO Server [message #1019376 is a reply to message #1019369] Fri, 15 March 2013 15:07 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 743
Registered: July 2009
Senior Member
You could start your bundle that contains your own extension at a higher start level than cdo/net4j.
If you are using a product definition to export your server, you can configure the start level of each bundle in the "Configuration" section.


Anders Jönsson wrote on Fri, 15 March 2013 15:57
Hi (again),


Is there a way to get notified when the CDO server has completed its startup (I thought IAppExtension would be it)?


In order to be able to run my own code in a cdo server application and specifically to start it in an orderly fashion i implemented an org.eclipse.emf.cdo.spi.server.IAppExtension.

In the IAppExtension I configure a CDOSession and start a CDOTransaction to the same server (which is currently beeing started).

It turns out there is no guarantee that the server is started, which may occasionally render an exception of type:
org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate TCPClientConnector[localhost:2,036]

It seems to be the "Net4j extension starting" part that may or may not have happened before the IAppExtensions are called.

///Anders


Re: [CDO] Start own bundle in CDO Server [message #1019399 is a reply to message #1019369] Fri, 15 March 2013 15:42 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 919
Registered: July 2009
Senior Member
On 15-03-13 15:57, Anders Jönsson wrote:
> Hi (again),
>
>
> Is there a way to get notified when the CDO server has completed its
> startup (I thought IAppExtension would be it)?
>
>
> In order to be able to run my own code in a cdo server application and
> specifically to start it in an orderly fashion i implemented an
> org.eclipse.emf.cdo.spi.server.IAppExtension.
>
> In the IAppExtension I configure a CDOSession and start a CDOTransaction
> to the same server (which is currently beeing started).
>
> It turns out there is no guarantee that the server is started, which may
> occasionally render an exception of type:
> org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate
> TCPClientConnector[localhost:2,036]
>
The way we do it:

CDO has plugin extenstion points like here:

<extension
point="org.eclipse.net4j.util.elementProcessors">
<elementProcessor

class="com.netxforge.netxstudio.server.job.JobHandler$Initializer">
</elementProcessor>
</extension>

The class must implement IElementProcessor

public Object process(IManagedContainer container, String productGroup,
String factoryType, String description, Object element) {
if (element instanceof IRepository) {
final IRepository repository = (IRepository) element;
repository.addListener(new LifecycleEventAdapter() {
@Override
public void notifyLifecycleEvent(ILifecycleEvent event) {
if (event.getKind() == Kind.ACTIVATED) {
...DO YOUR THINGY HERE
}
});
}
return element;
}





> It seems to be the "Net4j extension starting" part that may or may not
> have happened before the IAppExtensions are called.
>
> ///Anders
>
>
Re: [CDO] Start own bundle in CDO Server [message #1019456 is a reply to message #1019399] Fri, 15 March 2013 18:23 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Am 15.03.2013 16:42, schrieb Christophe Bouhier:
> [...] The way we do it:
>
> CDO has plugin extenstion points like here:
>
> <extension
> point="org.eclipse.net4j.util.elementProcessors">
> <elementProcessor
>
> class="com.netxforge.netxstudio.server.job.JobHandler$Initializer">
> </elementProcessor>
> </extension>
>
> The class must implement IElementProcessor
>
> public Object process(IManagedContainer container, String productGroup,
> String factoryType, String description, Object element) {
> if (element instanceof IRepository) {
> final IRepository repository = (IRepository) element;
> repository.addListener(new LifecycleEventAdapter() {
> @Override
> public void notifyLifecycleEvent(ILifecycleEvent event) {
> if (event.getKind() == Kind.ACTIVATED) {
> ...DO YOUR THINGY HERE
> }
> });
> }
> return element;
> }
That's what I was going to suggest ;-)

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Start own bundle in CDO Server [message #1019474 is a reply to message #1019456] Fri, 15 March 2013 19:19 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Am 15.03.2013 19:23, schrieb Eike Stepper:
> Am 15.03.2013 16:42, schrieb Christophe Bouhier:
>> [...] The way we do it:
>>
>> CDO has plugin extenstion points like here:
>>
>> <extension
>> point="org.eclipse.net4j.util.elementProcessors">
>> <elementProcessor
>>
>> class="com.netxforge.netxstudio.server.job.JobHandler$Initializer">
>> </elementProcessor>
>> </extension>
>>
>> The class must implement IElementProcessor
>>
>> public Object process(IManagedContainer container, String productGroup,
>> String factoryType, String description, Object element) {
>> if (element instanceof IRepository) {
>> final IRepository repository = (IRepository) element;
>> repository.addListener(new LifecycleEventAdapter() {
>> @Override
>> public void notifyLifecycleEvent(ILifecycleEvent event) {
>> if (event.getKind() == Kind.ACTIVATED) {
>> ...DO YOUR THINGY HERE
>> }
>> });
>> }
>> return element;
>> }
> That's what I was going to suggest ;-)
Oh, and you can do the same thing with the configured acceptor!

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Start own bundle in CDO Server [message #1021126 is a reply to message #1019474] Tue, 19 March 2013 15:03 Go to previous messageGo to next message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
Hi, thanks for suggestions!

But, when i put my thingy in place of the "...DO YOUR THINGY HERE" thingy I still get an exception:
org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate TCPClientConnector[127.0.0.1:2,036]

The "thingy" here beeing that I am trying to create a CDOSession to the server using tcp (apparently I should use "jvm transport" instead but I haven't gotten around to that yet).

And the output below still happens after that (at least it is PRINTED to the log after the stack trace):
[INFO] Net4j extension starting

!ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.627
!MESSAGE Net4j extension starting
[INFO] Net4j extension started

!ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.641
!MESSAGE Net4j extension started

[INFO] CDO server started

!ENTRY org.eclipse.emf.cdo.server 1 0 2013-03-19 15:30:43.642
!MESSAGE CDO server started


Also; Eike, can you give me a little more hint about what "the configured acceptor" is.

///Anders
Re: [CDO] Start own bundle in CDO Server [message #1021193 is a reply to message #1021126] Tue, 19 March 2013 16:27 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 919
Registered: July 2009
Senior Member
On 19-03-13 16:03, Anders Jönsson wrote:
> Hi, thanks for suggestions!
>
> But, when i put my thingy in place of the "...DO YOUR THINGY HERE"
> thingy I still get an exception:
> org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate
> TCPClientConnector[127.0.0.1:2,036]
>
Is your code capable to open a TCPClientConnector without the Extension
mechanism that I described earlier?

> The "thingy" here beeing that I am trying to create a CDOSession to the
> server using tcp (apparently I should use "jvm transport" instead but I
> haven't gotten around to that yet).
>
ah, that's a different issue.
here is a snippet.

final IManagedContainer container = IPluginContainer.INSTANCE;
acceptor = JVMUtil.getAcceptor(container, "default");
connector = JVMUtil.getConnector(container, "default");

// Create configuration
final CDONet4jSessionConfiguration sessionConfiguration = CDONet4jUtil
.createNet4jSessionConfiguration();

sessionConfiguration.setConnector(connector);
sessionConfiguration.setRepositoryName(REPO_NAME);

> And the output below still happens after that (at least it is PRINTED to
> the log after the stack trace):
> [INFO] Net4j extension starting
>
> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.627
> !MESSAGE Net4j extension starting
> [INFO] Net4j extension started
>
> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.641
> !MESSAGE Net4j extension started
>
> [INFO] CDO server started
>
> !ENTRY org.eclipse.emf.cdo.server 1 0 2013-03-19 15:30:43.642
> !MESSAGE CDO server started
>
>
> Also; Eike, can you give me a little more hint about what "the
> configured acceptor" is.
>
> ///Anders
>
Re: [CDO] Start own bundle in CDO Server [message #1021194 is a reply to message #1021193] Tue, 19 March 2013 16:28 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 919
Registered: July 2009
Senior Member
On 19-03-13 17:27, Christophe Bouhier wrote:
> On 19-03-13 16:03, Anders Jönsson wrote:
>> Hi, thanks for suggestions!

BTW, I really recommend to checkout the cdo test plugin, it has tons of
examples.

>>
>> But, when i put my thingy in place of the "...DO YOUR THINGY HERE"
>> thingy I still get an exception:
>> org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate
>> TCPClientConnector[127.0.0.1:2,036]
>>
> Is your code capable to open a TCPClientConnector without the Extension
> mechanism that I described earlier?
>
>> The "thingy" here beeing that I am trying to create a CDOSession to the
>> server using tcp (apparently I should use "jvm transport" instead but I
>> haven't gotten around to that yet).
>>
> ah, that's a different issue.
> here is a snippet.
>
> final IManagedContainer container = IPluginContainer.INSTANCE;
> acceptor = JVMUtil.getAcceptor(container, "default");
> connector = JVMUtil.getConnector(container, "default");
>
> // Create configuration
> final CDONet4jSessionConfiguration sessionConfiguration =
> CDONet4jUtil
> .createNet4jSessionConfiguration();
>
> sessionConfiguration.setConnector(connector);
> sessionConfiguration.setRepositoryName(REPO_NAME);
>
>> And the output below still happens after that (at least it is PRINTED to
>> the log after the stack trace):
>> [INFO] Net4j extension starting
>>
>> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.627
>> !MESSAGE Net4j extension starting
>> [INFO] Net4j extension started
>>
>> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.641
>> !MESSAGE Net4j extension started
>>
>> [INFO] CDO server started
>>
>> !ENTRY org.eclipse.emf.cdo.server 1 0 2013-03-19 15:30:43.642
>> !MESSAGE CDO server started
>>
>>
>> Also; Eike, can you give me a little more hint about what "the
>> configured acceptor" is.
>>
>> ///Anders
>>
>
Re: [CDO] Start own bundle in CDO Server [message #1021219 is a reply to message #1021126] Tue, 19 March 2013 17:16 Go to previous messageGo to next message
Eike Stepper is currently offline Eike Stepper
Messages: 5523
Registered: July 2009
Senior Member
Hej Anders,

I meant that if you rely on a TCP connection to the repository you should not listen for repository activation but for
the TCP acceptor activation, in Christophe's words:

public Object process(IManagedContainer container, String productGroup,
String factoryType, String description, Object element) {
if (element instanceof ITCPAcceptor) {
final ITCPAcceptor acceptor = (ITCPAcceptor) element;
acceptor.addListener(new LifecycleEventAdapter() {
@Override
public void notifyLifecycleEvent(ILifecycleEvent event) {
if (event.getKind() == Kind.ACTIVATED) {
...DO YOUR THINGY HERE
}
});
}
return element;
}

The acceptor is always started after the repository, i.e. in the Net4j extension.

Does that help?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 19.03.2013 16:03, schrieb Anders Jönsson:
> Hi, thanks for suggestions!
>
> But, when i put my thingy in place of the "...DO YOUR THINGY HERE" thingy I still get an exception:
> org.eclipse.net4j.util.lifecycle.LifecycleException: Could not activate TCPClientConnector[127.0.0.1:2,036]
>
> The "thingy" here beeing that I am trying to create a CDOSession to the server using tcp (apparently I should use "jvm
> transport" instead but I haven't gotten around to that yet).
>
> And the output below still happens after that (at least it is PRINTED to the log after the stack trace):
> [INFO] Net4j extension starting
>
> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.627
> !MESSAGE Net4j extension starting
> [INFO] Net4j extension started
>
> !ENTRY org.eclipse.emf.cdo.server.net4j 1 0 2013-03-19 15:30:43.641
> !MESSAGE Net4j extension started
>
> [INFO] CDO server started
>
> !ENTRY org.eclipse.emf.cdo.server 1 0 2013-03-19 15:30:43.642
> !MESSAGE CDO server started
>
>
> Also; Eike, can you give me a little more hint about what "the configured acceptor" is.
>
> ///Anders
>
Re: [CDO] Start own bundle in CDO Server [message #1021518 is a reply to message #1021219] Wed, 20 March 2013 09:09 Go to previous message
Anders  Jönsson is currently offline Anders Jönsson
Messages: 33
Registered: January 2012
Member
Hi,

Listening to ITCPAcceptor activation solves the problem!

Thanks also for the JVM acceptor snippet, will try that later.

Thanks a lot
///Anders


Previous Topic:[XCore] basicSet method generated multiple times
Next Topic:Create a view on a 'merged' feature maps
Goto Forum:
  


Current Time: Thu Sep 18 10:02:03 GMT 2014

Powered by FUDForum. Page generated in 0.61272 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software