⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elanp2pserver.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     ElanP2PServer.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//* * Created on Feb 17, 2004 * * First onset to make Elan a service provider for collaborative annotation services * */package mpi.eudico.p2p;import mpi.eudico.client.annotator.commands.CommandAction;import mpi.eudico.client.annotator.commands.ELANCommandFactory;import mpi.eudico.server.corpora.clom.Transcription;import net.jxta.credential.AuthenticationCredential;import net.jxta.credential.Credential;import net.jxta.discovery.DiscoveryService;import net.jxta.document.AdvertisementFactory;import net.jxta.document.MimeMediaType;import net.jxta.document.StructuredDocument;import net.jxta.document.StructuredTextDocument;import net.jxta.endpoint.Message;import net.jxta.exception.PeerGroupException;import net.jxta.id.IDFactory;import net.jxta.membership.Authenticator;import net.jxta.membership.MembershipService;import net.jxta.peergroup.PeerGroup;import net.jxta.peergroup.PeerGroupFactory;import net.jxta.peergroup.PeerGroupID;import net.jxta.pipe.InputPipe;import net.jxta.pipe.OutputPipe;import net.jxta.pipe.PipeID;import net.jxta.pipe.PipeMsgEvent;import net.jxta.pipe.PipeMsgListener;import net.jxta.pipe.PipeService;import net.jxta.platform.ModuleClassID;import net.jxta.platform.ModuleSpecID;import net.jxta.protocol.ModuleClassAdvertisement;import net.jxta.protocol.ModuleImplAdvertisement;import net.jxta.protocol.ModuleSpecAdvertisement;import net.jxta.protocol.PeerGroupAdvertisement;import net.jxta.protocol.PipeAdvertisement;import java.io.ByteArrayInputStream;import java.io.IOException;import java.io.InputStream;import java.io.StringWriter;/** * DOCUMENT ME! * * @author hennie */public class ElanP2PServer implements PipeMsgListener {    private static PeerGroup netGroup = null;    private static DiscoveryService netDiscoSvc;    //	private final static String SERVICE = "JXTASPEC:ELAN"; // service name    /** Holds value of property DOCUMENT ME! */    private final static String TAG = "DataTag"; // tag in message    /** Holds value of property DOCUMENT ME! */    private final static String COMMAND = "Command";    /** Holds value of property DOCUMENT ME! */    private final static String TRANSCRIPTION_ID = "TranscriptionID";    /** Holds value of property DOCUMENT ME! */    private final static String FILENAME = "pipeserver.adv"; // file containing pipe advert.    private PeerGroup sessionGroup = null;    private DiscoveryService sessionDiscoSvc;    private PipeService pipeSvc;    private InputPipe myPipe; // input pipe for the service    private Message msg; // message received on input pipe    private OutputPipe broadcastPipe;    private Transcription transcription;    /**     * Creates a new ElanP2PServer instance     *     * @param theTranscription DOCUMENT ME!     */    public ElanP2PServer(Transcription theTranscription) {        transcription = theTranscription;    }    /**     * DOCUMENT ME!     */    public static void initP2P() {        System.out.println("Setup Elan for p2p services");        startJxta();    }    private static void startJxta() {        try {            // create, and Start the default jxta NetPeerGroup            netGroup = PeerGroupFactory.newNetPeerGroup();        } catch (PeerGroupException e) {            // could not instanciate the group, print the stack and exit            System.out.println("fatal error : group creation failure");            e.printStackTrace();            return;        }        // get the discovery, and pipe service        System.out.println("Getting NetDiscoveryService");        netDiscoSvc = netGroup.getDiscoveryService();        //		System.out.println("Getting PipeService");        //		pipeSvc = group.getPipeService();          }    /**     * DOCUMENT ME!     */    public void startServer() {        sessionGroup = createGroup();        if (sessionGroup != null) {            joinGroup(sessionGroup);        }        try {            System.out.println("Share " + transcription.getName() +                " in p2p annotation session");            sessionDiscoSvc = sessionGroup.getDiscoveryService();            System.out.println("Getting Session PipeService");            pipeSvc = sessionGroup.getPipeService();            // Create the Module class advertisement associated with the service            // We build the module class advertisement using the Advertisement            // Factory class by passing it the type of the advertisement we            // want to construct. The Module class advertisement is a            // a very small advertisement that only advertises the existence            // of service. In order to access the service, a peer will            // have to discover the associated module spec advertisement.            ModuleClassAdvertisement mcadv = (ModuleClassAdvertisement) AdvertisementFactory.newAdvertisement(ModuleClassAdvertisement.getAdvertisementType());            mcadv.setName("JXTAMOD:ELAN");            mcadv.setDescription(                "First attempt to provide p2p annotation services");            ModuleClassID mcID = IDFactory.newModuleClassID();            mcadv.setModuleClassID(mcID);            // Ok the Module Class advertisement was created, just publish            // it in my local cache and to my peergroup. This            // is the NetPeerGroup            sessionDiscoSvc.publish(mcadv, DiscoveryService.ADV);            sessionDiscoSvc.remotePublish(mcadv, DiscoveryService.ADV);            // Create the Module Spec advertisement associated with the service            // We build the module Spec Advertisement using the advertisement            // Factory class by passing in the type of the advertisement we            // want to construct. The Module Spec advertisement will contain            // all the information necessary for a client to contact the service            // for instance it will contain a pipe advertisement to            // be used to contact the service            ModuleSpecAdvertisement mdadv = (ModuleSpecAdvertisement) AdvertisementFactory.newAdvertisement(ModuleSpecAdvertisement.getAdvertisementType());            // Setup some of the information field about the servive. In this            // example, we just set the name, provider and version and a pipe            // advertisement. The module creates an input pipes to listen            // on this pipe endpoint.            mdadv.setName(transcription.getName());            mdadv.setVersion("Version 1.0");            mdadv.setCreator("mpi.nl");            ModuleSpecID id = (ModuleSpecID) IDFactory.newModuleSpecID(mcID);            mdadv.setModuleSpecID(id);            mdadv.setSpecURI("http://www.mpi.nl/tools");            // Create a pipe advertisement for the Service. The client MUST use

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -