use of com.hazelcast.core.HazelcastException in project neo4j by neo4j.
the class HazelcastCoreTopologyService method createHazelcastInstance.
private HazelcastInstance createHazelcastInstance() {
System.setProperty(WAIT_SECONDS_BEFORE_JOIN.getName(), "1");
JoinConfig joinConfig = new JoinConfig();
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getAwsConfig().setEnabled(false);
TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
tcpIpConfig.setEnabled(true);
List<AdvertisedSocketAddress> initialMembers = config.get(CausalClusteringSettings.initial_discovery_members);
for (AdvertisedSocketAddress address : initialMembers) {
tcpIpConfig.addMember(address.toString());
}
Setting<ListenSocketAddress> discovery_listen_address = CausalClusteringSettings.discovery_listen_address;
ListenSocketAddress hazelcastAddress = config.get(discovery_listen_address);
InterfacesConfig interfaces = new InterfacesConfig();
interfaces.addInterface(hazelcastAddress.getHostname());
NetworkConfig networkConfig = new NetworkConfig();
networkConfig.setInterfaces(interfaces);
networkConfig.setPort(hazelcastAddress.getPort());
networkConfig.setJoin(joinConfig);
networkConfig.setPortAutoIncrement(false);
com.hazelcast.config.Config c = new com.hazelcast.config.Config();
c.setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), String.valueOf(10_000));
c.setProperty(MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
c.setProperty(MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
c.setProperty(INITIAL_MIN_CLUSTER_SIZE.getName(), String.valueOf(minimumClusterSizeThatCanTolerateOneFaultForExpectedClusterSize()));
c.setProperty(LOGGING_TYPE.getName(), "none");
c.setNetworkConfig(networkConfig);
MemberAttributeConfig memberAttributeConfig = HazelcastClusterTopology.buildMemberAttributesForCore(myself, config);
c.setMemberAttributeConfig(memberAttributeConfig);
logConnectionInfo(initialMembers);
JobScheduler.JobHandle logJob = scheduler.schedule("HazelcastHealth", HAZELCAST_IS_HEALTHY_TIMEOUT_MS, () -> log.warn("The server has not been able to connect in a timely fashion to the " + "cluster. Please consult the logs for more details. Rebooting the server may " + "solve the problem."));
try {
hazelcastInstance = Hazelcast.newHazelcastInstance(c);
logJob.cancel(true);
} catch (HazelcastException e) {
String errorMessage = String.format("Hazelcast was unable to start with setting: %s = %s", discovery_listen_address.name(), config.get(discovery_listen_address));
userLog.error(errorMessage);
log.error(errorMessage, e);
throw new RuntimeException(e);
}
List<String> groups = config.get(CausalClusteringSettings.server_groups);
refreshGroups(hazelcastInstance, myself.getUuid().toString(), groups);
return hazelcastInstance;
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class DefaultAddressPicker method getPublicAddressByPortSearch.
private AddressDefinition getPublicAddressByPortSearch() throws IOException {
NetworkConfig networkConfig = config.getNetworkConfig();
boolean bindAny = hazelcastProperties.getBoolean(GroupProperty.SOCKET_SERVER_BIND_ANY);
Throwable error = null;
ServerSocket serverSocket = null;
InetSocketAddress inetSocketAddress;
boolean reuseAddress = networkConfig.isReuseAddress();
logger.finest("inet reuseAddress:" + reuseAddress);
int port = networkConfig.getPort();
// port = 0 means system will pick up an ephemeral port.
int portTrialCount = port > 0 && networkConfig.isPortAutoIncrement() ? networkConfig.getPortCount() : 1;
AddressDefinition bindAddressDef = pickAddressDef();
if (port == 0) {
logger.info("No explicit port is given, system will pick up an ephemeral port.");
}
for (int i = 0; i < portTrialCount; i++) {
/*
* Instead of reusing the ServerSocket/ServerSocketChannel, we are going to close and replace them on
* every attempt to find a free port. The reason to do this is because in some cases, when concurrent
* threads/processes try to acquire the same port, the ServerSocket gets corrupted and isn't able to
* find any free port at all (no matter if there are more than enough free ports available). We have
* seen this happening on Linux and Windows environments.
*/
serverSocketChannel = ServerSocketChannel.open();
serverSocket = serverSocketChannel.socket();
serverSocket.setReuseAddress(reuseAddress);
serverSocket.setSoTimeout(SOCKET_TIMEOUT_MILLIS);
try {
if (bindAny) {
inetSocketAddress = new InetSocketAddress(port + i);
} else {
inetSocketAddress = new InetSocketAddress(bindAddressDef.inetAddress, port + i);
}
logger.fine("Trying to bind inet socket address: " + inetSocketAddress);
serverSocket.bind(inetSocketAddress, SOCKET_BACKLOG_LENGTH);
logger.fine("Bind successful to inet socket address: " + serverSocket.getLocalSocketAddress());
break;
} catch (Exception e) {
serverSocket.close();
serverSocketChannel.close();
error = e;
}
}
if (serverSocket == null || !serverSocket.isBound()) {
String message;
if (networkConfig.isPortAutoIncrement()) {
message = "ServerSocket bind has failed. Hazelcast cannot start. config-port: " + networkConfig.getPort() + ", latest-port: " + (port + portTrialCount);
} else {
message = "Port [" + port + "] is already in use and auto-increment is disabled." + " Hazelcast cannot start.";
}
throw new HazelcastException(message, error);
}
// get the actual port that's bound by server socket
port = serverSocket.getLocalPort();
serverSocketChannel.configureBlocking(false);
bindAddress = createAddress(bindAddressDef, port);
logger.info("Picked " + bindAddress + ", using socket " + serverSocket + ", bind any local is " + bindAny);
return getPublicAddress(port);
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class ClientConnectionManagerImpl method createSocketConnection.
protected ClientConnection createSocketConnection(final Address address) throws IOException {
if (!alive) {
throw new HazelcastException("ConnectionManager is not active!");
}
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
Socket socket = socketChannel.socket();
socket.setKeepAlive(socketOptions.isKeepAlive());
socket.setTcpNoDelay(socketOptions.isTcpNoDelay());
socket.setReuseAddress(socketOptions.isReuseAddress());
if (socketOptions.getLingerSeconds() > 0) {
socket.setSoLinger(true, socketOptions.getLingerSeconds());
}
int bufferSize = getBufferSize();
socket.setSendBufferSize(bufferSize);
socket.setReceiveBufferSize(bufferSize);
InetSocketAddress inetSocketAddress = address.getInetSocketAddress();
socketChannel.socket().connect(inetSocketAddress, connectionTimeout);
SocketChannelWrapper socketChannelWrapper = socketChannelWrapperFactory.wrapSocketChannel(socketChannel, true);
final ClientConnection clientConnection = new ClientConnection(client, ioThreadingModel, connectionIdGen.incrementAndGet(), socketChannelWrapper);
socketChannel.configureBlocking(true);
if (socketInterceptor != null) {
socketInterceptor.onConnect(socket);
}
socketChannel.configureBlocking(ioThreadingModel.isBlocking());
socket.setSoTimeout(0);
clientConnection.start();
return clientConnection;
} catch (Exception e) {
if (socketChannel != null) {
socketChannel.close();
}
throw ExceptionUtil.rethrow(e, IOException.class);
}
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class XmlClientConfigLocator method loadFromWorkingDirectory.
private boolean loadFromWorkingDirectory() {
File file = new File("hazelcast-client.xml");
if (!file.exists()) {
LOGGER.finest("Could not find 'hazelcast-client.xml' in working directory.");
return false;
}
LOGGER.info("Loading 'hazelcast-client.xml' from working directory.");
try {
in = new FileInputStream(file);
} catch (FileNotFoundException e) {
throw new HazelcastException("Failed to open file: " + file.getAbsolutePath(), e);
}
return true;
}
use of com.hazelcast.core.HazelcastException in project hazelcast by hazelcast.
the class XmlClientConfigLocator method loadSystemPropertyFileResource.
private void loadSystemPropertyFileResource(String configSystemProperty) {
//it is a file.
File configurationFile = new File(configSystemProperty);
LOGGER.info("Using configuration file at " + configurationFile.getAbsolutePath());
if (!configurationFile.exists()) {
String msg = "Config file at '" + configurationFile.getAbsolutePath() + "' doesn't exist.";
throw new HazelcastException(msg);
}
try {
in = new FileInputStream(configurationFile);
} catch (FileNotFoundException e) {
throw new HazelcastException("Failed to open file: " + configurationFile.getAbsolutePath(), e);
}
}
Aggregations