Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.zookeeper.server;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.management.JMException;
import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginException;
import org.apache.zookeeper.Environment;
import org.apache.zookeeper.Login;
import org.apache.zookeeper.common.ZKConfig;
import org.apache.zookeeper.jmx.MBeanRegistry;
import org.apache.zookeeper.server.auth.SaslServerCallbackHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class ServerCnxnFactory {
public static final String ZOOKEEPER_SERVER_CNXN_FACTORY = "zookeeper.serverCnxnFactory";
private static final String ZOOKEEPER_MAX_CONNECTION = "zookeeper.maxCnxns";
public static final int ZOOKEEPER_MAX_CONNECTION_DEFAULT = 0;
private static final Logger LOG = LoggerFactory.getLogger(ServerCnxnFactory.class);
// Tells whether SSL is enabled on this ServerCnxnFactory
protected boolean secure;
/**
* The buffer will cause the connection to be close when we do a send.
*/
static final ByteBuffer closeConn = ByteBuffer.allocate(0);
// total number of connections accepted by the ZooKeeper server
protected int maxCnxns;
// sessionMap is used by closeSession()
final ConcurrentHashMap sessionMap = new ConcurrentHashMap();
private static String loginUser = Login.SYSTEM_USER;
public void addSession(long sessionId, ServerCnxn cnxn) {
sessionMap.put(sessionId, cnxn);
}
public void removeCnxnFromSessionMap(ServerCnxn cnxn) {
long sessionId = cnxn.getSessionId();
if (sessionId != 0) {
sessionMap.remove(sessionId);
}
}
/**
* @return true if the cnxn that contains the sessionId exists in this ServerCnxnFactory
* and it's closed. Otherwise false.
*/
public boolean closeSession(long sessionId, ServerCnxn.DisconnectReason reason) {
ServerCnxn cnxn = sessionMap.remove(sessionId);
if (cnxn != null) {
try {
cnxn.close(reason);
} catch (Exception e) {
LOG.warn("exception during session close", e);
}
return true;
}
return false;
}
public abstract int getLocalPort();
public abstract Iterable getConnections();
public int getNumAliveConnections() {
return cnxns.size();
}
public final ZooKeeperServer getZooKeeperServer() {
return zkServer;
}
public void configure(InetSocketAddress addr, int maxcc) throws IOException {
configure(addr, maxcc, -1);
}
public void configure(InetSocketAddress addr, int maxcc, int backlog) throws IOException {
configure(addr, maxcc, backlog, false);
}
public abstract void configure(InetSocketAddress addr, int maxcc, int backlog, boolean secure) throws IOException;
public abstract void reconfigure(InetSocketAddress addr);
protected SaslServerCallbackHandler saslServerCallbackHandler;
public Login login;
/** Maximum number of connections allowed from particular host (ip) */
public abstract int getMaxClientCnxnsPerHost();
/** Maximum number of connections allowed from particular host (ip) */
public abstract void setMaxClientCnxnsPerHost(int max);
public boolean isSecure() {
return secure;
}
public void startup(ZooKeeperServer zkServer) throws IOException, InterruptedException {
startup(zkServer, true);
}
// This method is to maintain compatiblity of startup(zks) and enable sharing of zks
// when we add secureCnxnFactory.
public abstract void startup(ZooKeeperServer zkServer, boolean startServer) throws IOException, InterruptedException;
/** The maximum queue length of the ZooKeeper server's socket */
public abstract int getSocketListenBacklog();
public abstract void join() throws InterruptedException;
public abstract void shutdown();
public abstract void start();
protected ZooKeeperServer zkServer;
public final void setZooKeeperServer(ZooKeeperServer zks) {
this.zkServer = zks;
if (zks != null) {
if (secure) {
zks.setSecureServerCnxnFactory(this);
} else {
zks.setServerCnxnFactory(this);
}
}
}
public abstract void closeAll(ServerCnxn.DisconnectReason reason);
public static ServerCnxnFactory createFactory() throws IOException {
String serverCnxnFactoryName = System.getProperty(ZOOKEEPER_SERVER_CNXN_FACTORY);
if (serverCnxnFactoryName == null) {
serverCnxnFactoryName = NIOServerCnxnFactory.class.getName();
}
try {
ServerCnxnFactory serverCnxnFactory = (ServerCnxnFactory) Class.forName(serverCnxnFactoryName)
.getDeclaredConstructor()
.newInstance();
LOG.info("Using {} as server connection factory", serverCnxnFactoryName);
return serverCnxnFactory;
} catch (Exception e) {
IOException ioe = new IOException("Couldn't instantiate " + serverCnxnFactoryName, e);
throw ioe;
}
}
public static ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns) throws IOException {
return createFactory(new InetSocketAddress(clientPort), maxClientCnxns, -1);
}
public static ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns, int backlog) throws IOException {
return createFactory(new InetSocketAddress(clientPort), maxClientCnxns, backlog);
}
public static ServerCnxnFactory createFactory(InetSocketAddress addr, int maxClientCnxns) throws IOException {
return createFactory(addr, maxClientCnxns, -1);
}
public static ServerCnxnFactory createFactory(InetSocketAddress addr, int maxClientCnxns, int backlog) throws IOException {
ServerCnxnFactory factory = createFactory();
factory.configure(addr, maxClientCnxns, backlog);
return factory;
}
public abstract InetSocketAddress getLocalAddress();
public abstract void resetAllConnectionStats();
public abstract Iterable