Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [CDO] Starting server code
[CDO] Starting server code [message #117088] Mon, 07 April 2008 12:12 Go to next message
Matthias Treitler is currently offline Matthias TreitlerFriend
Messages: 117
Registered: July 2009
Senior Member
Hi Eike!

I do not succeed in setting up a CDO Server. Currently I am doing it the
programmatically way... Some time ago you provided two source files in
this newsgropu where it had been described how to set up the server.

Basically I have two plugins:
CdoServer and CdoClient.
The CdoServer uses the following code:
OMPlatform.INSTANCE.setDebugging(true);
OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOL E);

IManagedContainer container = ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container);
CDOServerUtil.prepareContainer(container);

// prepare store parameters
IMappingStrategy strategy = CDODBUtil
.createMappingStrategy("horizontal");

Map<String, String> mappingProps = new HashMap<String, String>();
mappingProps.put(MappingStrategy.PROP_MAPPING_PRECEDENCE, "MODEL");
mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
"LIKE_ATTRIBUTES");
mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
"ONE_TABLE_PER_REFERENCE");

strategy.setProperties(mappingProps);

IDBAdapter adapter = DBUtil.getDBAdapter("derby");

// DataSource dataSource = createEmbeddedDataSource(database);
DataSource dataSource = createClientDataSource(database);
IDBConnectionProvider provider = DBUtil
.createConnectionProvider(dataSource);

// Create a DBStore
IDBStore store = CDODBUtil.createStore(strategy, adapter, provider);
strategy.setStore(store);

// Create a repository
Map<String, String> props = new HashMap<String, String>();
props.put(Props.PROP_SUPPORTING_AUDITS, "true");
props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");// true does
not work
props.put(Props.PROP_VERIFYING_REVISIONS, "false");
props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");

IRepository repository = CDOServerUtil.createRepository(repositoryName,
store, props);

CDOServerUtil.addRepository(container, repository);

The createClientDataSource looks like the following:
private DataSource createClientDataSource(String database) {

ClientDataSource ds = new ClientDataSource();
ds.setDatabaseName(database);
ds.setCreateDatabase("create");

return ds;
}

When starting no log gets printed from the CDO plug-ins! Maybe I do not
know how to enable this behaviour.

The client uses the following connection code:
IManagedContainer container = ContainerUtil.createContainer();

Net4jUtil.prepareContainer(container);
CDOUtil.prepareContainer(container, true);
IAcceptor acceptor = null;

if (kind == ConnectionKind.TCP) {

TCPUtil.prepareContainer(container);

// Start the TCP transport
acceptor = TCPUtil.getAcceptor(container, host);

// Open a TCP connection
connector = TCPUtil.getConnector(container, host);

} else if (kind == ConnectionKind.JVM) {

JVMUtil.prepareContainer(container);

// Start the JVM transport
acceptor = JVMUtil.getAcceptor(container, "default");

// Open a JVM connection
connector = JVMUtil.getConnector(container, "default");

}

CDOSession session = null;

session = CDOUtil.openSession(connector, repository, true);

Variable host and kind are correctly initialized by me.
So when I start the server and the client wants to connect (either JVM or
TCP) the client hangs.
The problem is because the client gets no answer from the server in the
method call OpenSessionRequest.confirming().

So I guess the server is not initialized correctly because he does not
"react".
But the database is sucessfully created by CDO.

What am I doing wrong?!?

Best regards,
Matthias
Re: [CDO] Starting server code [message #117104 is a reply to message #117088] Mon, 07 April 2008 14:46 Go to previous message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Hi Matthias,

Hard to say what exactly the problem is without the traces. Have you
tried to step into some methods and look why tracing does not show up on
the console? When I ran your example, I could see it.
You said you're running standalone? Then you can't use the extension
point based helper methods in DBUtil and CDODBUtil. I've added
respective JavaDocs.
I have changed your code a bit and the server seems to run:

import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IRepository.Props;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.MappingStrategy;

import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
import org.eclipse.net4j.tcp.TCPUtil;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;

import org.apache.derby.jdbc.EmbeddedDataSource;

import javax.sql.DataSource;

import java.util.HashMap;
import java.util.Map;

public class Snippet
{
private static final String DATABASE = "/temp/cdotest";

public static void main(String[] args) throws Exception
{
OMPlatform.INSTANCE.setDebugging(true);
OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOL E);

IManagedContainer container = ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container);
TCPUtil.prepareContainer(container);
CDOServerUtil.prepareContainer(container);
LifecycleUtil.activate(container);

// prepare store parameters
IMappingStrategy strategy = CDODBUtil.createHorizontalMappingStrategy();

Map<String, String> mappingProps = new HashMap<String, String>();
mappingProps.put(MappingStrategy.PROP_MAPPING_PRECEDENCE, "MODEL");
mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
"LIKE_ATTRIBUTES");
mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
"ONE_TABLE_PER_REFERENCE");

strategy.setProperties(mappingProps);

IDBAdapter adapter = new EmbeddedDerbyAdapter();

DataSource dataSource = createEmbeddedDataSource(DATABASE);
// DataSource dataSource = createClientDataSource(DATABASE);
IDBConnectionProvider provider =
DBUtil.createConnectionProvider(dataSource);

// Create a DBStore
IDBStore store = CDODBUtil.createStore(strategy, adapter, provider);
strategy.setStore(store);

// Create a repository
Map<String, String> props = new HashMap<String, String>();
props.put(Props.PROP_SUPPORTING_AUDITS, "true");
props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");// true
does not work for DBStore
props.put(Props.PROP_VERIFYING_REVISIONS, "false");
props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");

IRepository repository = CDOServerUtil.createRepository("repo1",
store, props);
CDOServerUtil.addRepository(container, repository);

container.getElement("org.eclipse.net4j.acceptors", "tcp", null);
System.out.println("CDO server running, press any key to shut down...");
while (System.in.read() == -1)
{
Thread.sleep(100);
}

LifecycleUtil.deactivate(container);
}

private static EmbeddedDataSource createEmbeddedDataSource(String
database)
{
EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName(database);
ds.setCreateDatabase("create");
return ds;
}
}

Does that already help?

Cheers
/Eike



Matthias schrieb:
> Hi Eike!
>
> I do not succeed in setting up a CDO Server. Currently I am doing it
> the programmatically way... Some time ago you provided two source
> files in this newsgropu where it had been described how to set up the
> server.
>
> Basically I have two plugins:
> CdoServer and CdoClient.
> The CdoServer uses the following code:
> OMPlatform.INSTANCE.setDebugging(true);
> OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
> OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOL E);
>
> IManagedContainer container = ContainerUtil.createContainer();
> Net4jUtil.prepareContainer(container);
> CDOServerUtil.prepareContainer(container);
>
> // prepare store parameters
> IMappingStrategy strategy = CDODBUtil
> .createMappingStrategy("horizontal");
>
> Map<String, String> mappingProps = new HashMap<String, String>();
> mappingProps.put(MappingStrategy.PROP_MAPPING_PRECEDENCE,
> "MODEL");
>
> mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
> "LIKE_ATTRIBUTES");
>
> mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
> "ONE_TABLE_PER_REFERENCE");
>
> strategy.setProperties(mappingProps);
>
> IDBAdapter adapter = DBUtil.getDBAdapter("derby");
>
> // DataSource dataSource = createEmbeddedDataSource(database);
> DataSource dataSource = createClientDataSource(database);
> IDBConnectionProvider provider = DBUtil
> .createConnectionProvider(dataSource);
>
> // Create a DBStore
> IDBStore store = CDODBUtil.createStore(strategy, adapter,
> provider);
> strategy.setStore(store);
>
> // Create a repository
> Map<String, String> props = new HashMap<String, String>();
> props.put(Props.PROP_SUPPORTING_AUDITS, "true");
> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");//
> true does not work
> props.put(Props.PROP_VERIFYING_REVISIONS, "false");
> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>
> IRepository repository =
> CDOServerUtil.createRepository(repositoryName,
> store, props);
>
> CDOServerUtil.addRepository(container, repository);
>
> The createClientDataSource looks like the following:
> private DataSource createClientDataSource(String database) {
>
> ClientDataSource ds = new ClientDataSource();
> ds.setDatabaseName(database);
> ds.setCreateDatabase("create");
>
> return ds;
> }
>
> When starting no log gets printed from the CDO plug-ins! Maybe I do
> not know how to enable this behaviour.
>
> The client uses the following connection code:
> IManagedContainer container = ContainerUtil.createContainer();
>
> Net4jUtil.prepareContainer(container);
> CDOUtil.prepareContainer(container, true);
> IAcceptor acceptor = null;
>
> if (kind == ConnectionKind.TCP) {
>
> TCPUtil.prepareContainer(container);
>
> // Start the TCP transport
> acceptor = TCPUtil.getAcceptor(container, host);
>
> // Open a TCP connection
> connector = TCPUtil.getConnector(container, host);
>
> } else if (kind == ConnectionKind.JVM) {
>
> JVMUtil.prepareContainer(container);
>
> // Start the JVM transport
> acceptor = JVMUtil.getAcceptor(container, "default");
>
> // Open a JVM connection
> connector = JVMUtil.getConnector(container, "default");
>
> }
>
> CDOSession session = null;
>
> session = CDOUtil.openSession(connector, repository, true);
>
> Variable host and kind are correctly initialized by me.
> So when I start the server and the client wants to connect (either JVM
> or TCP) the client hangs. The problem is because the client gets no
> answer from the server in the method call
> OpenSessionRequest.confirming().
> So I guess the server is not initialized correctly because he does not
> "react".
> But the database is sucessfully created by CDO.
>
> What am I doing wrong?!?
>
> Best regards,
> Matthias
>
Re: [CDO] Starting server code [message #616093 is a reply to message #117088] Mon, 07 April 2008 14:46 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6580
Registered: July 2009
Senior Member
Hi Matthias,

Hard to say what exactly the problem is without the traces. Have you
tried to step into some methods and look why tracing does not show up on
the console? When I ran your example, I could see it.
You said you're running standalone? Then you can't use the extension
point based helper methods in DBUtil and CDODBUtil. I've added
respective JavaDocs.
I have changed your code a bit and the server seems to run:

import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IRepository.Props;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.MappingStrategy;

import org.eclipse.net4j.Net4jUtil;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
import org.eclipse.net4j.db.internal.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.internal.util.om.log.PrintLogHandler;
import org.eclipse.net4j.internal.util.om.trace.PrintTraceHandler;
import org.eclipse.net4j.tcp.TCPUtil;
import org.eclipse.net4j.util.container.ContainerUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;

import org.apache.derby.jdbc.EmbeddedDataSource;

import javax.sql.DataSource;

import java.util.HashMap;
import java.util.Map;

public class Snippet
{
private static final String DATABASE = "/temp/cdotest";

public static void main(String[] args) throws Exception
{
OMPlatform.INSTANCE.setDebugging(true);
OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOL E);

IManagedContainer container = ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container);
TCPUtil.prepareContainer(container);
CDOServerUtil.prepareContainer(container);
LifecycleUtil.activate(container);

// prepare store parameters
IMappingStrategy strategy = CDODBUtil.createHorizontalMappingStrategy();

Map<String, String> mappingProps = new HashMap<String, String>();
mappingProps.put(MappingStrategy.PROP_MAPPING_PRECEDENCE, "MODEL");
mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
"LIKE_ATTRIBUTES");
mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
"ONE_TABLE_PER_REFERENCE");

strategy.setProperties(mappingProps);

IDBAdapter adapter = new EmbeddedDerbyAdapter();

DataSource dataSource = createEmbeddedDataSource(DATABASE);
// DataSource dataSource = createClientDataSource(DATABASE);
IDBConnectionProvider provider =
DBUtil.createConnectionProvider(dataSource);

// Create a DBStore
IDBStore store = CDODBUtil.createStore(strategy, adapter, provider);
strategy.setStore(store);

// Create a repository
Map<String, String> props = new HashMap<String, String>();
props.put(Props.PROP_SUPPORTING_AUDITS, "true");
props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");// true
does not work for DBStore
props.put(Props.PROP_VERIFYING_REVISIONS, "false");
props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");

IRepository repository = CDOServerUtil.createRepository("repo1",
store, props);
CDOServerUtil.addRepository(container, repository);

container.getElement("org.eclipse.net4j.acceptors", "tcp", null);
System.out.println("CDO server running, press any key to shut down...");
while (System.in.read() == -1)
{
Thread.sleep(100);
}

LifecycleUtil.deactivate(container);
}

private static EmbeddedDataSource createEmbeddedDataSource(String
database)
{
EmbeddedDataSource ds = new EmbeddedDataSource();
ds.setDatabaseName(database);
ds.setCreateDatabase("create");
return ds;
}
}

Does that already help?

Cheers
/Eike



Matthias schrieb:
> Hi Eike!
>
> I do not succeed in setting up a CDO Server. Currently I am doing it
> the programmatically way... Some time ago you provided two source
> files in this newsgropu where it had been described how to set up the
> server.
>
> Basically I have two plugins:
> CdoServer and CdoClient.
> The CdoServer uses the following code:
> OMPlatform.INSTANCE.setDebugging(true);
> OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
> OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOL E);
>
> IManagedContainer container = ContainerUtil.createContainer();
> Net4jUtil.prepareContainer(container);
> CDOServerUtil.prepareContainer(container);
>
> // prepare store parameters
> IMappingStrategy strategy = CDODBUtil
> .createMappingStrategy("horizontal");
>
> Map<String, String> mappingProps = new HashMap<String, String>();
> mappingProps.put(MappingStrategy.PROP_MAPPING_PRECEDENCE,
> "MODEL");
>
> mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
> "LIKE_ATTRIBUTES");
>
> mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
> "ONE_TABLE_PER_REFERENCE");
>
> strategy.setProperties(mappingProps);
>
> IDBAdapter adapter = DBUtil.getDBAdapter("derby");
>
> // DataSource dataSource = createEmbeddedDataSource(database);
> DataSource dataSource = createClientDataSource(database);
> IDBConnectionProvider provider = DBUtil
> .createConnectionProvider(dataSource);
>
> // Create a DBStore
> IDBStore store = CDODBUtil.createStore(strategy, adapter,
> provider);
> strategy.setStore(store);
>
> // Create a repository
> Map<String, String> props = new HashMap<String, String>();
> props.put(Props.PROP_SUPPORTING_AUDITS, "true");
> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");//
> true does not work
> props.put(Props.PROP_VERIFYING_REVISIONS, "false");
> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>
> IRepository repository =
> CDOServerUtil.createRepository(repositoryName,
> store, props);
>
> CDOServerUtil.addRepository(container, repository);
>
> The createClientDataSource looks like the following:
> private DataSource createClientDataSource(String database) {
>
> ClientDataSource ds = new ClientDataSource();
> ds.setDatabaseName(database);
> ds.setCreateDatabase("create");
>
> return ds;
> }
>
> When starting no log gets printed from the CDO plug-ins! Maybe I do
> not know how to enable this behaviour.
>
> The client uses the following connection code:
> IManagedContainer container = ContainerUtil.createContainer();
>
> Net4jUtil.prepareContainer(container);
> CDOUtil.prepareContainer(container, true);
> IAcceptor acceptor = null;
>
> if (kind == ConnectionKind.TCP) {
>
> TCPUtil.prepareContainer(container);
>
> // Start the TCP transport
> acceptor = TCPUtil.getAcceptor(container, host);
>
> // Open a TCP connection
> connector = TCPUtil.getConnector(container, host);
>
> } else if (kind == ConnectionKind.JVM) {
>
> JVMUtil.prepareContainer(container);
>
> // Start the JVM transport
> acceptor = JVMUtil.getAcceptor(container, "default");
>
> // Open a JVM connection
> connector = JVMUtil.getConnector(container, "default");
>
> }
>
> CDOSession session = null;
>
> session = CDOUtil.openSession(connector, repository, true);
>
> Variable host and kind are correctly initialized by me.
> So when I start the server and the client wants to connect (either JVM
> or TCP) the client hangs. The problem is because the client gets no
> answer from the server in the method call
> OpenSessionRequest.confirming().
> So I guess the server is not initialized correctly because he does not
> "react".
> But the database is sucessfully created by CDO.
>
> What am I doing wrong?!?
>
> Best regards,
> Matthias
>


Previous Topic:[CDO] Starting server code
Next Topic:Column name for attribute override
Goto Forum:
  


Current Time: Fri Jun 25 11:24:13 GMT 2021

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

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

Back to the top