| /******************************************************************************* |
| * Copyright (c) 2013 RCP Vision (http://www.rcp-vision.com) and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Lorenzo Bettini - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.emf.parsley.cdo; |
| |
| import org.eclipse.emf.cdo.net4j.CDONet4jSessionConfiguration; |
| import org.eclipse.emf.cdo.net4j.CDONet4jUtil; |
| import org.eclipse.emf.cdo.session.CDOSession; |
| import org.eclipse.net4j.connector.IConnector; |
| import org.eclipse.net4j.util.container.IPluginContainer; |
| import org.eclipse.net4j.util.lifecycle.ILifecycle; |
| import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; |
| |
| public class CDOSessionManager { |
| |
| public CDOSession getSession(String server, String repository) { |
| |
| final IConnector connector = (IConnector) IPluginContainer.INSTANCE |
| .getElement( // |
| "org.eclipse.net4j.connectors", // Product group |
| "tcp", // Type |
| server); |
| |
| CDONet4jSessionConfiguration config = CDONet4jUtil |
| .createNet4jSessionConfiguration(); |
| config.setConnector(connector); |
| config.setRepositoryName(repository); |
| |
| CDOSession session = config.openNet4jSession(); |
| |
| session.addListener(new LifecycleEventAdapter() { |
| @Override |
| protected void onDeactivated(ILifecycle lifecycle) { |
| connector.close(); |
| } |
| }); |
| |
| return session; |
| |
| } |
| |
| } |