📄 abstractjamesservice.java
字号:
getLogger().info(infoBuffer.toString()); timeout = handlerConfiguration.getChild(TIMEOUT_NAME).getValueAsInteger(DEFAULT_TIMEOUT); infoBuffer = new StringBuffer(64) .append(getServiceType()) .append(" handler connection timeout is: ") .append(timeout); getLogger().info(infoBuffer.toString()); backlog = conf.getChild(BACKLOG_NAME).getValueAsInteger(DEFAULT_BACKLOG); infoBuffer = new StringBuffer(64) .append(getServiceType()) .append(" connection backlog is: ") .append(backlog); getLogger().info(infoBuffer.toString()); final String location = "generated:" + getServiceType(); if (connectionManager instanceof JamesConnectionManager) { String connectionLimitString = conf.getChild("connectionLimit").getValue(null); if (connectionLimitString != null) { try { connectionLimit = new Integer(connectionLimitString); } catch (NumberFormatException nfe) { getLogger().error("Connection limit value is not properly formatted.", nfe); } if (connectionLimit.intValue() < 0) { getLogger().error("Connection limit value cannot be less than zero."); throw new ConfigurationException("Connection limit value cannot be less than zero."); } } else { connectionLimit = new Integer(((JamesConnectionManager)connectionManager).getMaximumNumberOfOpenConnections()); } infoBuffer = new StringBuffer(128) .append(getServiceType()) .append(" will allow a maximum of ") .append(connectionLimit.intValue()) .append(" connections."); getLogger().info(infoBuffer.toString()); } } /** * @see org.apache.avalon.framework.activity.Initializable#initialize() */ public void initialize() throws Exception { if (!isEnabled()) { getLogger().info(getServiceType() + " Disabled"); System.out.println(getServiceType() + " Disabled"); return; } getLogger().debug(getServiceType() + " init..."); SocketManager socketManager = (SocketManager) compMgr.lookup(SocketManager.ROLE); ThreadManager threadManager = (ThreadManager) compMgr.lookup(ThreadManager.ROLE); if (threadGroup != null) { threadPool = threadManager.getThreadPool(threadGroup); } else { threadPool = threadManager.getDefaultThreadPool(); } ServerSocketFactory factory = socketManager.getServerSocketFactory(serverSocketType); ServerSocket serverSocket = factory.createServerSocket(port, backlog, bindTo); if (null == connectionName) { final StringBuffer sb = new StringBuffer(); sb.append(serverSocketType); sb.append(':'); sb.append(port); if (null != bindTo) { sb.append('/'); sb.append(bindTo); } connectionName = sb.toString(); } if ((connectionLimit != null) && (connectionManager instanceof JamesConnectionManager)) { if (null != threadPool) { ((JamesConnectionManager)connectionManager).connect(connectionName, serverSocket, this, threadPool, connectionLimit.intValue()); } else { ((JamesConnectionManager)connectionManager).connect(connectionName, serverSocket, this, connectionLimit.intValue()); // default pool } } else { if (null != threadPool) { connectionManager.connect(connectionName, serverSocket, this, threadPool); } else { connectionManager.connect(connectionName, serverSocket, this); // default pool } } getLogger().debug(getServiceType() + " ...init end"); StringBuffer logBuffer = new StringBuffer(64) .append(getServiceType()) .append(" started ") .append(connectionName); String logString = logBuffer.toString(); System.out.println(logString); getLogger().info(logString); } /** * @see org.apache.avalon.framework.activity.Disposable#dispose() */ public void dispose() { if (!isEnabled()) { return; } StringBuffer infoBuffer = new StringBuffer(64) .append(getServiceType()) .append(" dispose... ") .append(connectionName); getLogger().debug(infoBuffer.toString()); try { connectionManager.disconnect(connectionName, true); } catch (final Exception e) { StringBuffer warnBuffer = new StringBuffer(64) .append("Error disconnecting ") .append(getServiceType()) .append(": "); getLogger().warn(warnBuffer.toString(), e); } compMgr = null; connectionManager = null; threadPool = null; // This is needed to make sure sockets are promptly closed on Windows 2000 // TODO: Check this - shouldn't need to explicitly gc to force socket closure System.gc(); getLogger().debug(getServiceType() + " ...dispose end"); } /** * This constructs the WatchdogFactory that will be used to guard * against runaway or stuck behavior. Should only be called once * by a subclass in its initialize() method. * * @return the WatchdogFactory to be employed by subclasses. */ protected WatchdogFactory getWatchdogFactory() { WatchdogFactory theWatchdogFactory = null; theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout); if (theWatchdogFactory instanceof LogEnabled) { ((LogEnabled)theWatchdogFactory).enableLogging(getLogger()); } return theWatchdogFactory; } /** * Describes whether this service is enabled by configuration. * * @return is the service enabled. */ public final boolean isEnabled() { return enabled; } /** * Overide this method to create actual instance of connection handler. * * @return the new ConnectionHandler * @exception Exception if an error occurs */ protected abstract ConnectionHandler newHandler() throws Exception; /** * Get the default port for this server type. * * It is strongly recommended that subclasses of this class * override this method to specify the default port for their * specific server type. * * @return the default port */ protected int getDefaultPort() { return 0; } /** * Get whether TLS is enabled for this server's socket by default. * * @return the default port */ protected boolean isDefaultTLSEnabled() { return false; } /** * This method returns the type of service provided by this server. * This should be invariant over the life of the class. * * Subclasses may override this implementation. This implementation * parses the complete class name and returns the undecorated class * name. * * @return description of this server */ public String getServiceType() { String name = getClass().getName(); int p = name.lastIndexOf("."); if (p > 0 && p < name.length() - 2) { name = name.substring(p + 1); } return name; } /** * Returns the port that the service is bound to * * @return int The port number */ public int getPort() { return port; } /** * Returns the address if the network interface the socket is bound to * * @return String The network interface name */ public String getNetworkInterface() { if (bindTo == null) { return "All"; } else { return bindTo.getHostAddress(); } } /** * Returns the server socket type, plain or SSL * * @return String The scoekt type, plain or SSL */ public String getSocketType() { return serverSocketType; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -