| /******************************************************************************* |
| * Copyright (c) 2008-2011 Chair for Applied Software Engineering, |
| * Technische Universitaet Muenchen. |
| * 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: |
| ******************************************************************************/ |
| package org.eclipse.emf.emfstore.backchannel.example.client; |
| |
| import org.eclipse.emf.emfstore.client.backchannel.BackchannelConnectionManager; |
| import org.eclipse.emf.emfstore.client.model.ServerInfo; |
| import org.eclipse.emf.emfstore.client.model.connectionmanager.KeyStoreManager; |
| import org.eclipse.emf.emfstore.client.proxy.ProxyClient; |
| import org.eclipse.emf.emfstore.common.model.util.ModelUtil; |
| import org.eclipse.emf.emfstore.common.model.util.SerializationException; |
| import org.eclipse.emf.emfstore.server.exceptions.EmfStoreException; |
| import org.eclipse.emf.emfstore.server.internal.eventmanager.EMFStoreEventListener; |
| import org.eclipse.emf.emfstore.server.model.ProjectInfo; |
| import org.eclipse.emf.emfstore.server.model.versioning.events.server.ServerEvent; |
| |
| /** |
| * Demo client using the backchannel. |
| * |
| * @author ovonwesen |
| */ |
| public class DemoBackchannelClient extends ProxyClient { |
| |
| /** |
| * Runs the client. |
| */ |
| public void run() { |
| try { |
| loginServer("super", "super", "localhost", null, KeyStoreManager.DEFAULT_CERTIFICATE, 8080); |
| |
| BackchannelConnectionManager manager = new BackchannelConnectionManager(); |
| manager.initConnection(getBackChannelServerInfo(), getSessionId()); |
| |
| EMFStoreEventListener listener = new EMFStoreEventListener() { |
| public boolean handleEvent(ServerEvent event) { |
| try { |
| System.out.println(ModelUtil.eObjectToString(event)); |
| } catch (SerializationException e) { |
| e.printStackTrace(); |
| } |
| return true; |
| } |
| }; |
| |
| for (ProjectInfo info : getProjectList()) { |
| try { |
| manager.registerRemoteListener(getSessionId(), listener, info.getProjectId()); |
| System.out.println("registered listener at project: " + info.getName()); |
| } catch (EmfStoreException e) { |
| System.out.println("Error while registring project: " + info.getName() + ", " + e.toString()); |
| } |
| } |
| |
| while (!Thread.currentThread().isInterrupted()) { |
| Thread.sleep(1000); |
| } |
| // BEGIN SUPRESS CATCH EXCEPTION |
| } catch (Exception e) { |
| e.printStackTrace(); |
| // END sSUPRESS CATCH EXCEPTION |
| } |
| } |
| |
| private ServerInfo getBackChannelServerInfo() { |
| return getServerInfo("localhost", KeyStoreManager.DEFAULT_CERTIFICATE, 8080); |
| } |
| } |