public <T> T sendAndReceiveFixedConnection(Connection conn, Object obj) throws IOException { final SerializationService serializationService = getSerializationService(); final Data request = serializationService.toData(obj); conn.write(request); final Data response = conn.read(); final Object result = serializationService.toObject(response); return ErrorHandler.returnResultOrThrowException(result); }
private Object authenticate( Connection connection, Credentials credentials, ClientPrincipal principal, boolean reAuth, boolean firstConnection) throws IOException { AuthenticationRequest auth = new AuthenticationRequest(credentials, principal); auth.setReAuth(reAuth); auth.setFirstConnection(firstConnection); final SerializationService serializationService = getSerializationService(); connection.write(serializationService.toData(auth)); final Data addressData = connection.read(); Address address = ErrorHandler.returnResultOrThrowException(serializationService.toObject(addressData)); connection.setRemoteEndpoint(address); final Data data = connection.read(); return ErrorHandler.returnResultOrThrowException(serializationService.toObject(data)); }
private <T> T _sendAndReceive(ConnectionFactory connectionFactory, Object obj) throws IOException { while (active) { Connection conn = null; boolean release = true; try { conn = connectionFactory.create(); final SerializationService serializationService = getSerializationService(); final Data request = serializationService.toData(obj); conn.write(request); final Data response = conn.read(); final Object result = serializationService.toObject(response); return ErrorHandler.returnResultOrThrowException(result); } catch (Exception e) { if (e instanceof IOException) { if (logger.isFinestEnabled()) { logger.finest("Error on connection... conn: " + conn + ", error: " + e); } IOUtil.closeResource(conn); release = false; } if (ErrorHandler.isRetryable(e)) { if (redoOperation || obj instanceof RetryableRequest) { if (logger.isFinestEnabled()) { logger.finest("Retrying " + obj + ", last-conn: " + conn + ", last-error: " + e); } beforeRetry(); continue; } } if (e instanceof IOException && !active) { continue; } throw ExceptionUtil.rethrow(e, IOException.class); } finally { if (release && conn != null) { conn.release(); } } } throw new HazelcastInstanceNotActiveException(); }
private void loadInitialMemberList() throws IOException { final SerializationService serializationService = getSerializationService(); final Data request = serializationService.toData(new AddMembershipListenerRequest()); conn.write(request); final Data response = conn.read(); SerializableCollection coll = ErrorHandler.returnResultOrThrowException(serializationService.toObject(response)); Map<String, MemberImpl> prevMembers = Collections.emptyMap(); if (!members.isEmpty()) { prevMembers = new HashMap<String, MemberImpl>(members.size()); for (MemberImpl member : members) { prevMembers.put(member.getUuid(), member); } members.clear(); } for (Data d : coll.getCollection()) { members.add((MemberImpl) serializationService.toObject(d)); } updateMembersRef(); logger.info(membersString()); final List<MembershipEvent> events = new LinkedList<MembershipEvent>(); final Set<Member> eventMembers = Collections.unmodifiableSet(new LinkedHashSet<Member>(members)); for (MemberImpl member : members) { final MemberImpl former = prevMembers.remove(member.getUuid()); if (former == null) { events.add( new MembershipEvent( client.getCluster(), member, MembershipEvent.MEMBER_ADDED, eventMembers)); } } for (MemberImpl member : prevMembers.values()) { events.add( new MembershipEvent( client.getCluster(), member, MembershipEvent.MEMBER_REMOVED, eventMembers)); } for (MembershipEvent event : events) { fireMembershipEvent(event); } }