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

📄 servlethttptransport.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // determine the local interface to use. If the user specifies        // one, use that. Otherwise, use the all the available interfaces.        String interfaceAddressStr = httpAdv.getInterfaceAddress();        boolean publicAddressOnly = httpAdv.getPublicAddressOnly();                if (interfaceAddressStr != null) {            try {                usingInterface = InetAddress.getByName(interfaceAddressStr);            } catch (UnknownHostException failed) {                if (LOG.isEnabledFor(Level.WARN)) {                    LOG.warn("Invalid address for local interface address, using default");                }                usingInterface = IPUtils.ANYADDRESS;            }        } else {            usingInterface = IPUtils.ANYADDRESS;        }                usingPort = httpAdv.getPort();                configClient = httpAdv.isClientEnabled();                configServer = httpAdv.isServerEnabled();                publicAddresses = getPublicAddresses(configServer, httpAdv.getServer(), usingInterface, usingPort, publicAddressOnly);                if (!configClient && !configServer) {            throw new IllegalArgumentException("Neither incoming nor outgoing connections configured.");        }                publicAddress = (EndpointAddress) publicAddresses.get(0);                // Tell tell the world about our configuration.        if (LOG.isEnabledFor(Level.INFO)) {            StringBuffer configInfo = new StringBuffer("Configuring HTTP Message Transport : " + assignedID);                        if (implAdvertisement != null) {                configInfo.append("\n\tImplementation:");                configInfo.append("\n\t\tModule Spec ID: " + implAdvertisement.getModuleSpecID());                configInfo.append("\n\t\tImpl Description: " + implAdvertisement.getDescription());                configInfo.append("\n\t\tImpl URI: " + implAdvertisement.getUri());                configInfo.append("\n\t\tImpl Code: " + implAdvertisement.getCode());            }                        configInfo.append("\n\tGroup Params:");            configInfo.append("\n\t\tGroup: " + group.getPeerGroupName());            configInfo.append("\n\t\tGroup ID: " + group.getPeerGroupID());            configInfo.append("\n\t\tPeer ID: " + group.getPeerID());                        configInfo.append("\n\tConfiguration :");            configInfo.append("\n\t\tProtocol: " + httpAdv.getProtocol());            configInfo.append("\n\t\tClient Enabled: " + configClient);            configInfo.append("\n\t\tServer Enabled: " + configServer);            configInfo.append("\n\t\tPublic address: " + (httpAdv.getServer() == null ? "(unspecified)" : httpAdv.getServer()));            configInfo.append("\n\t\tInterface address: " + (interfaceAddressStr == null ? "(unspecified)" : interfaceAddressStr));            configInfo.append("\n\t\tUnicast Server Bind Addr: " + IPUtils.getHostAddress(usingInterface) + ":" + usingPort);            configInfo.append("\n\t\tPublic Addresses: ");            configInfo.append("\n\t\t\tDefault Endpoint Addr : " + publicAddress);                        Iterator eachPublic = publicAddresses.iterator();                        while (eachPublic.hasNext()) {                EndpointAddress anAddr = (EndpointAddress) eachPublic.next();                                configInfo.append("\n\t\t\tEndpoint Addr : " + anAddr);            }                        LOG.info(configInfo);        }    }        /**     * {@inheritDoc}     **/    public synchronized int startApp(String[] args) {        endpoint = group.getEndpointService();                if (null == endpoint) {            if (LOG.isEnabledFor(Level.WARN)) {                LOG.warn("Stalled until there is an endpoint service");            }                        return START_AGAIN_STALLED;        }                if (TransportMeterBuildSettings.TRANSPORT_METERING) {            TransportServiceMonitor transportServiceMonitor = (TransportServiceMonitor) MonitorManager.getServiceMonitor(group,                    MonitorResources.transportServiceMonitorClassID);                        if (transportServiceMonitor != null) {                transportMeter = transportServiceMonitor.createTransportMeter("HTTP", publicAddress.toString());                unknownTransportBindingMeter = transportMeter.getTransportBindingMeter(TransportMeter.UNKNOWN_PEER, TransportMeter.UNKNOWN_ADDRESS);            }        }                if (configServer) {            // Start the http server that runs the receiver.                        try {                receiver = new HttpMessageReceiver(this, publicAddresses, usingInterface, usingPort);                receiver.start();            } catch (PeerGroupException e) {                if (LOG.isEnabledFor(Level.ERROR)) {                    LOG.error("Could not start http message receiver", e);                }                return -1; // Can't go on; if we were configured to be a server we must make the failure obvious.            }        }                if (configClient) {            // create the MessageSender                        try {                sender = new HttpMessageSender(this, new EndpointAddress( "jxta", group.getPeerID().getUniqueValue().toString(), null, null) );                sender.start();            } catch (PeerGroupException e) {                if (LOG.isEnabledFor(Level.ERROR)) {                    LOG.error("Could not start http message sender", e);                }                return -1; // Can't go on; if we were configured to be a server we must make the failure obvious.            }        }                return 0;    }        /**     * {@inheritDoc}     **/    public synchronized void stopApp() {        if (receiver != null) {            receiver.stop();        }                if (sender != null) {            sender.stop();        }                endpoint = null;    }        /**     * {@inheritDoc}     **/    public EndpointService getEndpointService() {        return endpoint;    }        private List getPublicAddresses(boolean serverEnabled,            String serverName,            InetAddress usingInterface,            int serverSocketPort,            boolean publicAddressOnly            ) {        List publicAddresses = new ArrayList();                if (serverEnabled) {            // Build the publicAddresses                        // first in the list is the "public server name". We don't try to            // resolve this since it might not be resolvable in the context            // we are running in, we just assume it's good.            if (serverName != null) {                // use speced server name.                EndpointAddress newAddr = new EndpointAddress(HTTP_PROTOCOL_NAME, serverName, null, null);                                publicAddresses.add(newAddr);                if (publicAddressOnly) {                    return publicAddresses;                }            }        }                // then add the rest of the local interfaces as appropriate        if (usingInterface.equals(IPUtils.ANYADDRESS)) {            // its wildcarded            Iterator eachLocal = IPUtils.getAllLocalAddresses();            List wildAddrs = new ArrayList();                        while (eachLocal.hasNext()) {                InetAddress anAddress = (InetAddress) eachLocal.next();                                String hostAddress = IPUtils.getHostAddress(anAddress);                                EndpointAddress newAddr = new EndpointAddress(HTTP_PROTOCOL_NAME, hostAddress + ":" + Integer.toString(serverSocketPort),                        null, null);                                // don't add it if its already in the list                if (!publicAddresses.contains(newAddr)) {                    wildAddrs.add(newAddr);                }            }                        // we sort them so that later equals() will be deterministic.            // the result of IPUtils.getAllLocalAddresses() is not known            // to be sorted.            Collections.sort(wildAddrs, new Comparator() {                                public int compare(Object one, Object two) {                    return one.toString().compareTo(two.toString());                }                                public boolean equals(Object that) {                    return (this == that);                }            });                        publicAddresses.addAll(wildAddrs);        } else {            // use speced interface            String hostAddress = IPUtils.getHostAddress(usingInterface);                        EndpointAddress newAddr = new EndpointAddress(HTTP_PROTOCOL_NAME, hostAddress + ":" + Integer.toString(serverSocketPort),                    null, null);                        // don't add it if its already in the list            if (!publicAddresses.contains(newAddr)) {                publicAddresses.add(newAddr);            }        }                return publicAddresses;    }        TransportBindingMeter getTransportBindingMeter(String peerIDString, EndpointAddress destinationAddress) {        if (transportMeter != null) {            return transportMeter.getTransportBindingMeter((peerIDString != null) ? peerIDString : TransportMeter.UNKNOWN_PEER, destinationAddress);        } else {            return null;        }    }        TransportBindingMeter getUnknownTransportBindingMeter() {        return unknownTransportBindingMeter;    }}

⌨️ 快捷键说明

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