Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] Starting sequence of IAppExtensions
[CDO] Starting sequence of IAppExtensions [message #959372] Fri, 26 October 2012 17:11 Go to next message
Christoph Keimel is currently online Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Hello

I have created an IAppExtension for our CDO/Hibernate server. This extension uses JVM to connect to the server.

My problem is: Depending on the starting order of the IAppExtensions, I sometimes get an error that the JVM acceptor "default:0" could not be found. I found that the acceptor is initiated with the Net4jAppExtension. So when Net4jAppExtension is started first everything is fine. If my new AppExtension is started first, it can't connect.

The acceptor is defined in the cdo-server.xml:

<cdoServer>
    <acceptor type="jvm" listenAddr="default" port="0"/>
    <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"/>

    ...
</cdoServer>


This is the code that establishes the JVM session:
private CDOSession openSession() {
	if (sessionConfiguration == null) {
		logger.info("Initialisiere CDO Configuration ...");
		initialize();
	}
	final CDONet4jSession cdoSession = sessionConfiguration.openNet4jSession();
	return cdoSession;
}

private void initialize() {
	// Prepare container
	final IManagedContainer container = ContainerUtil.createContainer();
	Net4jUtil.prepareContainer(container); // Register Net4j factories
	JVMUtil.prepareContainer(container); // Register JVM factories
	CDONet4jUtil.prepareContainer(container); // Register CDO factories
	container.activate();

	// Create connector
	if (connector == null) {
		logger.info("Erstelle JVMUtil Connector");
		connector = JVMUtil.getConnector(container, "default:0");
	}

	// Create configuration
	logger.info("Erstelle CDOSessionConfiguration zu: {}", REPO_NAME);
	sessionConfiguration = CDONet4jUtil.createNet4jSessionConfiguration();
	sessionConfiguration.setConnector(connector);
	sessionConfiguration.setRepositoryName(REPO_NAME);
}


My questions are:
1. Do I need to initialize the acceptor? If yes, how?
2. Is it possible to set the order of AppExtension execution?

Any additional hints are also most welcome.

Thank you!
Christoph
Re: [CDO] Starting sequence of IAppExtensions [message #960223 is a reply to message #959372] Sat, 27 October 2012 09:30 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5574
Registered: July 2009
Senior Member
Hi Christoph,

I think this has been asked before but I couldn't find that thread either. The solution is to listen to IContainerEvents
from IPluginContainer.INSTANCE, if the repository/acceptor is not available there immediately. You can overwrite
ContainerEventAdapter.onAdded() to react to later container element additions. Does that help?

Cheers
/Eike

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



Am 26.10.2012 19:11, schrieb Christoph Keimel:
> Hello
>
> I have created an IAppExtension for our CDO/Hibernate server. This extension uses JVM to connect to the server.
>
> My problem is: Depending on the starting order of the IAppExtensions, I sometimes get an error that the JVM acceptor
> "default:0" could not be found. I found that the acceptor is initiated with the Net4jAppExtension. So when
> Net4jAppExtension is started first everything is fine. If my new AppExtension is started first, it can't connect.
>
> The acceptor is defined in the cdo-server.xml:
>
> <cdoServer>
> <acceptor type="jvm" listenAddr="default" port="0"/>
> <acceptor type="tcp" listenAddr="0.0.0.0" port="2036"/>
>
> ...
> </cdoServer>
>
>
> This is the code that establishes the JVM session:
> private CDOSession openSession() {
> if (sessionConfiguration == null) {
> logger.info("Initialisiere CDO Configuration ...");
> initialize();
> }
> final CDONet4jSession cdoSession = sessionConfiguration.openNet4jSession();
> return cdoSession;
> }
>
> private void initialize() {
> // Prepare container
> final IManagedContainer container = ContainerUtil.createContainer();
> Net4jUtil.prepareContainer(container); // Register Net4j factories
> JVMUtil.prepareContainer(container); // Register JVM factories
> CDONet4jUtil.prepareContainer(container); // Register CDO factories
> container.activate();
>
> // Create connector
> if (connector == null) {
> logger.info("Erstelle JVMUtil Connector");
> connector = JVMUtil.getConnector(container, "default:0");
> }
>
> // Create configuration
> logger.info("Erstelle CDOSessionConfiguration zu: {}", REPO_NAME);
> sessionConfiguration = CDONet4jUtil.createNet4jSessionConfiguration();
> sessionConfiguration.setConnector(connector);
> sessionConfiguration.setRepositoryName(REPO_NAME);
> }
>
> My questions are:
> 1. Do I need to initialize the acceptor? If yes, how?
> 2. Is it possible to set the order of AppExtension execution?
>
> Any additional hints are also most welcome.
>
> Thank you!
> Christoph
Re: [CDO] Starting sequence of IAppExtensions [message #961501 is a reply to message #960223] Sun, 28 October 2012 10:26 Go to previous messageGo to next message
Christoph Keimel is currently online Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Hi Eike,

thanks for the Input. I'm still stuck though, so I would be gratefull if you could give me another pointer.

This is the way I am processing at the moment:
private void process() {
	final IManagedContainer container = createContainer();
	try {
		logger.info("Erstelle JVMUtil Connector");
		IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);
		continueProcess(connector);
	} catch (IllegalStateException e) {
		logger.info("Installiere ContainerListener");
		IPluginContainer.INSTANCE.addListener(new ContainerEventAdapter<Object>() {
			@Override
			protected void onAdded(IContainer<Object> cont, Object element) {
				if (element instanceof JVMAcceptor) {
					JVMAcceptor acceptor = (JVMAcceptor) element;
					if (acceptor.getName().equals(ACCEPTOR_NAME)) {
						logger.info("Erstelle JVMUtil Connector");
						//JVMUtil.getAcceptor(container, ACCEPTOR_NAME);
						IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);
						//IConnector connector = JVMUtil.getConnector(IPluginContainer.INSTANCE, ACCEPTOR_NAME);
						continueProcess(connector);
					}
					IPluginContainer.INSTANCE.removeListener(this);
				}
			}
		});
	}
}

I am waiting for the Acceptor to be added before I continue with the processing. This still leads to the same error because the Acceptor is still not available in my container and passing IPluginContainer.INSTANCE to JVMUtil.getConnector produces the same result.

If I manually add the Acceptor with JVMUtil.getAcceptor, I get a different exception:
org.eclipse.net4j.channel.ChannelException: org.eclipse.net4j.util.container.FactoryNotFoundException: Factory not found: org.eclipse.net4j.serverProtocols[cdo]
	at org.eclipse.net4j.internal.jvm.JVMConnector.registerChannelWithPeer(JVMConnector.java:135)
	...

Which I don't realy understand since this factory is contributed by the plug-in org.eclipse.emf.cdo.server.net4j which is part of my product configuration and it should be activated, since the listener is triggered by code in the Net4jAppExtension contributed by the same plug-in.

I was looking for an event signalling the end of the startup process, but couldn't see anything in CdoServerApp. Starting the IAppExtension(s) is the last thing that happens, so I am not sure what I am missing.

Greetings
Christoph
Re: [CDO] Starting sequence of IAppExtensions [message #961515 is a reply to message #961501] Sun, 28 October 2012 10:38 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5574
Registered: July 2009
Senior Member
Hi Christophe,

It's probably easier to not depend on other IAppExtensions at all. You could create the JVMAcceptor/JVMCOnnector pair in
your own extension.

More comments below...


Am 28.10.2012 11:26, schrieb Christoph Keimel:
> Hi Eike,
>
> thanks for the Input. I'm still stuck though, so I would be gratefull if you could give me another pointer.
>
> This is the way I am processing at the moment:
> private void process() {
> final IManagedContainer container = createContainer();
> try {
> logger.info("Erstelle JVMUtil Connector");
> IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);
> continueProcess(connector);
> } catch (IllegalStateException e) {
> logger.info("Installiere ContainerListener");
> IPluginContainer.INSTANCE.addListener(new ContainerEventAdapter<Object>() {
> @Override
> protected void onAdded(IContainer<Object> cont, Object element) {
> if (element instanceof JVMAcceptor) {
> JVMAcceptor acceptor = (JVMAcceptor) element;
> if (acceptor.getName().equals(ACCEPTOR_NAME)) {
> logger.info("Erstelle JVMUtil Connector");
> //JVMUtil.getAcceptor(container, ACCEPTOR_NAME);
> IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);
> //IConnector connector = JVMUtil.getConnector(IPluginContainer.INSTANCE, ACCEPTOR_NAME);
> continueProcess(connector);
> }
> IPluginContainer.INSTANCE.removeListener(this);
> }
> }
> });
> }
> }
> I am waiting for the Acceptor to be added before I continue with the processing. This still leads to the same error
> because the Acceptor is still not available in my container and passing IPluginContainer.INSTANCE to
> JVMUtil.getConnector produces the same result.
>
> If I manually add the Acceptor with JVMUtil.getAcceptor, I get a different exception:
> org.eclipse.net4j.channel.ChannelException: org.eclipse.net4j.util.container.FactoryNotFoundException: Factory not
> found: org.eclipse.net4j.serverProtocols[cdo]
> at org.eclipse.net4j.internal.jvm.JVMConnector.registerChannelWithPeer(JVMConnector.java:135)
> ...
>
> Which I don't realy understand since this factory is contributed by the plug-in org.eclipse.emf.cdo.server.net4j which
> is part of my product configuration and it should be activated,
And is it? You can check on the OSGi console with "ss".

> since the listener is triggered by code in the Net4jAppExtension contributed by the same plug-in.
>
> I was looking for an event signalling the end of the startup process, but couldn't see anything in CdoServerApp.
> Starting the IAppExtension(s) is the last thing that happens, so I am not sure what I am missing.
These things are so dependent on your deployment. Can you provide me with a small and executable example?

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Starting sequence of IAppExtensions [message #961565 is a reply to message #961515] Sun, 28 October 2012 11:34 Go to previous messageGo to next message
Christoph Keimel is currently online Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Hi Eike,

> It's probably easier to not depend on other IAppExtensions at all.

Yes. I don't realy want to depend on Net4jAppExtension. The way I read the source, this extionsion is responsible for reading the config and creating the acceptors.

> You could create the JVMAcceptor/JVMCOnnector pair in your own extension.

Yes, I think I will go for this solution: Take the jvm acceptor out of the cdo-server.xml and configure it by hand.

> And is it? You can check on the OSGi console with "ss".

The plug-in is activated:
16 ACTIVE org.eclipse.emf.cdo.server.net4j_4.0.100.qualifier

> These things are so dependent on your deployment. Can you provide me with a small and executable example?

I tried to create an example deployment. It is based on hibernate using mysql. I don't know, if you will be able to reproduce the error, because it depends on the order in which the extensions are executed ... if the Net4j extension runs first everything is fine. (Which is exactly what is happening when I execute the test here Sad )

Thanks for your support!

Greetings
Christoph
Re: [CDO] Starting sequence of IAppExtensions [message #961582 is a reply to message #961565] Sun, 28 October 2012 11:55 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
Did you try to set the start level of your plugin to a higher value than org.eclipse.emf.cdo.server.net4j?
This way, your extension will *always* start later than net4j's...
Re: [CDO] Starting sequence of IAppExtensions [message #961613 is a reply to message #961565] Sun, 28 October 2012 12:32 Go to previous messageGo to next message
Christoph Keimel is currently online Christoph KeimelFriend
Messages: 386
Registered: December 2010
Location: Germany
Senior Member
Hi Everybody,

I found the solution to the problem. Instead of creating my own container, I need to use IPluginContainer.INSTANCE from the beginning. I also removed the acceptor from cdo-server.xml. The acceptor is now manually created with: JVMUtil.getAcceptor(IPluginContainer.INSTANCE, ACCEPTOR_NAME).

So it's actually very simple to start a JMV connection independent from the Net4jAppExtension:
public void start(File configFile) throws Exception {
	IManagedContainer container = IPluginContainer.INSTANCE;
	JVMUtil.getAcceptor(container, ACCEPTOR_NAME);
	IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);

	sessionConfiguration = CDONet4jUtil.createNet4jSessionConfiguration();
	sessionConfiguration.setConnector(connector);
	sessionConfiguration.setRepositoryName(REPO_NAME);
	
	CDOSession session = sessionConfiguration.openNet4jSession();
	...
}


Thanks for the help.
Christoph
Re: [CDO] Starting sequence of IAppExtensions [message #961767 is a reply to message #961613] Sun, 28 October 2012 15:27 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5574
Registered: July 2009
Senior Member
Am 28.10.2012 13:32, schrieb Christoph Keimel:
> Hi Everybody,
>
> I found the solution to the problem. Instead of creating my own container, I need to use IPluginContainer.INSTANCE
> from the beginning.
Oh, I overlooked this in your first post:

// Prepare container
final IManagedContainer container = ContainerUtil.createContainer();

> I also removed the acceptor from cdo-server.xml. The acceptor is now manually created with:
> JVMUtil.getAcceptor(IPluginContainer.INSTANCE, ACCEPTOR_NAME).
>
> So it's actually very simple to start a JMV connection independent from the Net4jAppExtension:
> public void start(File configFile) throws Exception {
> IManagedContainer container = IPluginContainer.INSTANCE;
> JVMUtil.getAcceptor(container, ACCEPTOR_NAME);
Yes, that's basically the same what happens in the Net4jAppExtension.

> IConnector connector = JVMUtil.getConnector(container, ACCEPTOR_NAME);
>
> sessionConfiguration = CDONet4jUtil.createNet4jSessionConfiguration();
> sessionConfiguration.setConnector(connector);
> sessionConfiguration.setRepositoryName(REPO_NAME);
>
> CDOSession session = sessionConfiguration.openNet4jSession();
> ...
> }
>
> Thanks for the help.
Good that you figured out how to do it ;-)

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Re: [CDO] Starting sequence of IAppExtensions [message #961768 is a reply to message #961582] Sun, 28 October 2012 15:27 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5574
Registered: July 2009
Senior Member
Am 28.10.2012 12:55, schrieb Erdal Karaca:
> Did you try to set the start level of your plugin to a higher value than org.eclipse.emf.cdo.server.net4j?
> This way, your extension will *always* start later than net4j's...
Good idea! I must remember this...

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Previous Topic:Understanding CDO
Next Topic:serialize non-containment reference
Goto Forum:
  


Current Time: Wed Nov 26 16:26:30 GMT 2014

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

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