/**
         * Creates a direct connection to the given peer identifier, which, in the case of direct connect, is simply the
         * peer's hostname or IP address.
         */
        public TerkUserPrx connectToPeer(string peerIdentifier)
        {
            log("connectToPeer called");
            peerIdentifier = peerIdentifier.Replace("localhost", "127.0.0.1");

            HostAndPort hostAndPort = createHostAndPort(peerIdentifier);

            if (peerHostAndPortToProxyMap.ContainsKey(hostAndPort))
            {
                throw new DuplicateConnectionException("Already connected to peer [" + hostAndPort + "]");
            }

            log("Not connected... creating new connection");
            TerkUserPrx peerProxy;
            ObjectPrx   objectPrx;

            try
            {
                objectPrx = getPeerProxy(hostAndPort, new Identity(MAIN_SERVANT_PROXY_IDENTITY_NAME, ""));
                if (objectPrx != null)
                {
                    peerProxy = TerkUserPrxHelper.uncheckedCast(objectPrx);

                    peerHostAndPortToProxyMap.Add(hostAndPort, peerProxy);

                    //start pinger
                    pinger = startPinger(new PeerPingerState(hostAndPort, objectPrx, this));
                    peerHostAndPortToPingerMap.Add(hostAndPort, pinger);
                }

                else
                {
                    throw new PeerConnectionFailedException("getPeerProxy() returned null peer proxy for peer [" + hostAndPort + "]");
                }
            }
            catch (Exception e)
            {
                throw new PeerConnectionFailedException("Failed to create connection to peer [" + hostAndPort + "]: " + e);
            }
            HostInformation hostInformation = HostInformation.extractHostInformation(objectPrx.ice_getConnection().ToString());
            string          endpointKey     = objectAdapterName + "." + ENDPOINT_PROPERTY_KEY;
            string          endpointValue   = communicator.getProperties().getProperty(PROTOCOL_PROPERTY_KEY) + " -h " + hostInformation.getLocalHost() + " -p " + hostInformation.getLocalPort();

            communicator.getProperties().setProperty(endpointKey, endpointValue);

            peerProxy.ice_getConnection().setAdapter(addObjectAdapter(getObjectAdapterName()));

            servants = this.servantFactory.createServants(this);

            // notify the peer of the connection
            notifyPeerOfConnection(peerProxy);

            return(peerProxy);
        }
Esempio n. 2
0
        public Servants createServants(DirectConnectCommunicator communicator)
        {
            Trace.TraceError("QwerkClientServantFactory.createServants()");

            TerkUserServant mainServant = new TerkUserServant(communicator.getCommunicator());

            ObjectAdapter adapter = communicator.addObjectAdapter(communicator.getObjectAdapterName());

            ObjectPrx mainServantProxy = adapter.add(mainServant, new Identity(DirectConnectCommunicator.MAIN_SERVANT_PROXY_IDENTITY_NAME, ""));

            TerkUserPrx mainServantPrx = TerkUserPrxHelper.uncheckedCast(mainServantProxy);

            return(new Servants(mainServantPrx, mainServantPrx));
        }