📄 connector.java
字号:
package net.sf.dz.daemon.tcp;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.InetAddress;import java.net.ServerSocket;import java.net.Socket;import java.net.SocketException;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import java.util.TreeSet;import javax.net.ssl.SSLException;import org.freehold.jukebox.conf.Configuration;import org.freehold.jukebox.logger.LogChannel;import org.freehold.jukebox.sem.SemaphoreGroup;import org.freehold.jukebox.service.ActiveService;import org.freehold.jukebox.service.PassiveService;import org.freehold.jukebox.service.ServiceUnavailableException;import net.sf.dz.daemon.Server;import net.sf.dz.daemon.ServerModule;import net.sf.dz.daemon.onewire.OneWireServer;import net.sf.dz.daemon.onewire.OneWireContainerListener;import net.sf.dz.util.HostHelper;import net.sf.dz.util.SSLContextFactory;import net.sf.dz.pnp.MulticastServer;import net.sf.dz.pnp.custom.SimpleBroadcastServer;import net.sf.dz.pnp.custom.SimpleMulticastServer;// VT: FIXME: This class needs to be moved into a different package, along// with Broadcaster and Controllerimport net.sf.dz.daemon.tcp.server.AbstractListener;/** * The TCP connector. * * Provides a listener service and basic functionality common to the {@link * Broadcaster broadcaster} and the {@link Controller controller}. * * @author Copyright © <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001-2002 * @version $Id: Connector.java,v 1.18 2004/06/28 20:35:47 vtt Exp $ */abstract public class Connector extends AbstractListener implements ServerModule, OneWireContainerListener { /** * The server we're attached to. */ protected Server server; /** * Set of known device addresses. * * @see #deviceArrived * @see #deviceDeparted */ private Set deviceSet = new TreeSet(); /** * Set of 1-Wire servers we're talking to. */ protected Set serverSet = new HashSet(); public final void attach(Server server) { // VT: FIXME: check if attached already and blow up if yes this.server = server; } protected void configure2() { Configuration cf = getConfiguration(); String cfroot = getConfigurationRoot(); } protected void startup2() throws Throwable { // Check if we're configured getConfiguration(); if ( server == null ) { throw new IllegalStateException("Not attached to the server yet"); } // Register ourselves with the 1-Wire server[s] int count = 0; for ( Iterator i = server.getModuleMap().keySet().iterator(); i.hasNext(); ) { Object key = i.next(); Object module = server.getModuleMap().get(key); if ( module instanceof OneWireServer ) { complain(LOG_INFO, getLogChannel(), "1-Wire server found as '" + key + "'"); OneWireServer s = (OneWireServer)module; count++; s.addListener(this); serverSet.add(s); } } if ( count == 0 ) { throw new IllegalStateException("OneWireServer has to be defined in the configuration and operable before this module"); } } abstract protected void shutdown2(Throwable cause) throws Throwable; public void deviceArrived(String address, String type) { deviceSet.add(address); broadcastArrival(address, type); } public void deviceDeparted(String address) { deviceSet.remove(address); broadcastDeparture(address); } public void deviceFault(String address, String message) { broadcastFault(address, message); } abstract protected void broadcastArrival(String address, String type); protected void broadcastDeparture(String address) { } protected void broadcastFault(String address, String message) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -