public void setAsMaster() { logger.finest("This node is being set as the master"); masterAddress = address; setJoined(); this.getClusterService().getClusterClock().setClusterStartTime(Clock.currentTimeMillis()); this.getClusterService().setClusterId(UuidUtil.createClusterUuid()); }
public void onRestart() { joined.set(false); joiner.reset(); final String uuid = UuidUtil.createMemberUuid(address); logger.finest("Generated new UUID for local member: " + uuid); localMember.setUuid(uuid); }
@Test public void testMemberLeftException_usingSimpleMember() throws Exception { String uuid = UuidUtil.newUnsecureUuidString(); String host = "127.0.0.1"; int port = 5000; Member member = new SimpleMemberImpl(MemberVersion.of("3.8.0"), uuid, new InetSocketAddress(host, port)); testMemberLeftException(uuid, host, port, member); }
@Test public void testMemberLeftException_usingMemberImpl() throws Exception { String uuid = UuidUtil.newUnsecureUuidString(); String host = "127.0.0.1"; int port = 5000; Member member = new MemberImpl(new Address(host, port), MemberVersion.of("3.8.0"), false, uuid, null); testMemberLeftException(uuid, host, port, member); }
ClientEndpoint createEndpoint(Connection conn) { if (!conn.live()) { LOGGER.severe("Can't create and endpoint for a dead connection"); return null; } String clientUuid = UuidUtil.createClientUuid(conn.getEndPoint()); ClientEndpoint endpoint = new ClientEndpoint(clientEngine, conn, clientUuid); if (endpoints.putIfAbsent(conn, endpoint) != null) { LOGGER.severe("An endpoint already exists for connection:" + conn); } return endpoint; }
public TransactionImpl( TransactionManagerServiceImpl transactionManagerService, NodeEngine nodeEngine, TransactionOptions options, String txOwnerUuid) { this.transactionManagerService = transactionManagerService; this.nodeEngine = nodeEngine; this.txnId = UuidUtil.buildRandomUuidString(); this.timeoutMillis = options.getTimeoutMillis(); this.durability = options.getDurability(); this.transactionType = options.getTransactionType(); this.txOwnerUuid = txOwnerUuid == null ? nodeEngine.getLocalMember().getUuid() : txOwnerUuid; this.checkThreadAccess = txOwnerUuid != null; }
@Override public String registerListener(ListenerMessageCodec codec, EventHandler handler) { String userRegistrationId = UuidUtil.newUnsecureUuidString(); synchronized (listenerRegLock) { ClientRegistrationKey registrationKey = new ClientRegistrationKey(userRegistrationId, handler, codec); registrations.put(registrationKey, new ConcurrentHashMap<Address, ClientEventRegistration>()); try { for (Member member : this.members) { invoke(registrationKey, member.getAddress()); } } catch (Exception e) { deregisterListener(userRegistrationId); throw new HazelcastException("Listener can not be added", e); } return userRegistrationId; } }
public ClientEndpoint createNew(Connection conn) { return new ClientEndpoint( ClientEngineImpl.this, conn, UuidUtil.createClientUuid(conn.getEndPoint())); }
public Node(HazelcastInstanceImpl hazelcastInstance, Config config, NodeContext nodeContext) { this.hazelcastInstance = hazelcastInstance; this.threadGroup = hazelcastInstance.threadGroup; this.config = config; configClassLoader = config.getClassLoader(); this.groupProperties = new GroupProperties(config); SerializationService ss; try { ss = new SerializationServiceBuilder() .setClassLoader(configClassLoader) .setConfig(config.getSerializationConfig()) .setManagedContext(hazelcastInstance.managedContext) .setHazelcastInstance(hazelcastInstance) .build(); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } serializationService = (SerializationServiceImpl) ss; systemLogService = new SystemLogService(groupProperties.SYSTEM_LOG_ENABLED.getBoolean()); final AddressPicker addressPicker = nodeContext.createAddressPicker(this); try { addressPicker.pickAddress(); } catch (Throwable e) { throw ExceptionUtil.rethrow(e); } final ServerSocketChannel serverSocketChannel = addressPicker.getServerSocketChannel(); address = addressPicker.getPublicAddress(); localMember = new MemberImpl(address, true, UuidUtil.createMemberUuid(address)); String loggingType = groupProperties.LOGGING_TYPE.getString(); loggingService = new LoggingServiceImpl( systemLogService, config.getGroupConfig().getName(), loggingType, localMember); logger = loggingService.getLogger(Node.class.getName()); initializer = NodeInitializerFactory.create(configClassLoader); try { initializer.beforeInitialize(this); } catch (Throwable e) { try { serverSocketChannel.close(); } catch (Throwable ignored) { } throw ExceptionUtil.rethrow(e); } securityContext = config.getSecurityConfig().isEnabled() ? initializer.getSecurityContext() : null; nodeEngine = new NodeEngineImpl(this); clientEngine = new ClientEngineImpl(this); connectionManager = nodeContext.createConnectionManager(this, serverSocketChannel); partitionService = new PartitionServiceImpl(this); clusterService = new ClusterServiceImpl(this); textCommandService = new TextCommandServiceImpl(this); initializer.printNodeInfo(this); buildNumber = initializer.getBuildNumber(); VersionCheck.check(this, initializer.getBuild(), initializer.getVersion()); JoinConfig join = config.getNetworkConfig().getJoin(); MulticastService mcService = null; try { if (join.getMulticastConfig().isEnabled()) { MulticastConfig multicastConfig = join.getMulticastConfig(); MulticastSocket multicastSocket = new MulticastSocket(null); multicastSocket.setReuseAddress(true); // bind to receive interface multicastSocket.bind(new InetSocketAddress(multicastConfig.getMulticastPort())); multicastSocket.setTimeToLive(multicastConfig.getMulticastTimeToLive()); try { // set the send interface final Address bindAddress = addressPicker.getBindAddress(); // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4417033 // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6402758 if (!bindAddress.getInetAddress().isLoopbackAddress()) { multicastSocket.setInterface(bindAddress.getInetAddress()); } } catch (Exception e) { logger.warning(e); } multicastSocket.setReceiveBufferSize(64 * 1024); multicastSocket.setSendBufferSize(64 * 1024); String multicastGroup = System.getProperty("hazelcast.multicast.group"); if (multicastGroup == null) { multicastGroup = multicastConfig.getMulticastGroup(); } multicastConfig.setMulticastGroup(multicastGroup); multicastSocket.joinGroup(InetAddress.getByName(multicastGroup)); multicastSocket.setSoTimeout(1000); mcService = new MulticastService(this, multicastSocket); mcService.addMulticastListener(new NodeMulticastListener(this)); } } catch (Exception e) { logger.severe(e); } this.multicastService = mcService; initializeListeners(config); joiner = nodeContext.createJoiner(this); }
public String addMembershipListener(MembershipListener listener) { final String id = UuidUtil.buildRandomUuidString(); listeners.put(id, listener); return id; }
private String getUuid() { if (principal != null) { return principal.getUuid(); } return UuidUtil.createClientUuid(endpoint.getConnection().getEndPoint()); }