private static void _registerClusterOrder( HttpServletRequest request, ClusterNode clusterNode, String orderUuid, String productEntryName, int maxServers) throws Exception { MethodHandler methodHandler = new MethodHandler(_registerOrderMethodKey, orderUuid, productEntryName, maxServers); ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, clusterNode.getClusterNodeId()); FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest); ClusterNodeResponses clusterNodeResponses = futureClusterResponses.get(20000, TimeUnit.MILLISECONDS); ClusterNodeResponse clusterNodeResponse = clusterNodeResponses.getClusterResponse(clusterNode); Map<String, Object> attributes = (Map<String, Object>) clusterNodeResponse.getResult(); for (Map.Entry<String, Object> entry : attributes.entrySet()) { request.setAttribute( clusterNode.getClusterNodeId() + StringPool.UNDERLINE + entry.getKey(), entry.getValue()); } }
@AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class}) @Test public void testInvoke2() throws Exception { ClusterExecutorImpl clusterExecutorImpl1 = null; ClusterExecutorImpl clusterExecutorImpl2 = null; try { clusterExecutorImpl1 = getClusterExecutorImpl(false, false); clusterExecutorImpl2 = getClusterExecutorImpl(false, false); String timestamp = String.valueOf(System.currentTimeMillis()); MethodHandler methodHandler = new MethodHandler(testMethod1MethodKey, timestamp); Address address = clusterExecutorImpl2.getLocalClusterNodeAddress(); ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address); FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest); assertFutureClusterResponsesWithoutException( futureClusterResponses.get(), clusterRequest.getUuid(), timestamp, address); } finally { if (clusterExecutorImpl1 != null) { clusterExecutorImpl1.destroy(); } if (clusterExecutorImpl2 != null) { clusterExecutorImpl2.destroy(); } } }
@AdviseWith(adviceClasses = {EnableClusterLinkAdvice.class}) @Test public void testInvoke6() throws Exception { ClusterExecutorImpl clusterExecutorImpl1 = null; ClusterExecutorImpl clusterExecutorImpl2 = null; try { clusterExecutorImpl1 = getClusterExecutorImpl(false, true); clusterExecutorImpl2 = getClusterExecutorImpl(false, true); MethodHandler methodHandler = new MethodHandler(testMethod4MethodKey); Address address = clusterExecutorImpl2.getLocalClusterNodeAddress(); ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(methodHandler, address); clusterRequest.setBeanIdentifier(BEAN_IDENTIFIER); FutureClusterResponses futureClusterResponses = clusterExecutorImpl1.execute(clusterRequest); assertFutureClusterResponsesWithoutException( futureClusterResponses.get(), clusterRequest.getUuid(), SERIALIZABLE_RETRUN_VALUE, address); } finally { if (clusterExecutorImpl1 != null) { clusterExecutorImpl1.destroy(); } if (clusterExecutorImpl2 != null) { clusterExecutorImpl2.destroy(); } } }
private ObjectValuePair<String, URL> _getBootupClusterNodeObjectValuePair(Address bootupAddress) { ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest( new MethodHandler(_createTokenMethodKey, _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT), bootupAddress); FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest); BlockingQueue<ClusterNodeResponse> clusterNodeResponses = futureClusterResponses.getPartialResults(); try { ClusterNodeResponse clusterNodeResponse = clusterNodeResponses.poll( _CLUSTER_LINK_NODE_BOOTUP_RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); ClusterNode clusterNode = clusterNodeResponse.getClusterNode(); InetSocketAddress inetSocketAddress = clusterNode.getPortalInetSocketAddress(); if (inetSocketAddress == null) { StringBundler sb = new StringBundler(6); sb.append("Invalid cluster node InetSocketAddress "); sb.append(". The InetSocketAddress is set by the first "); sb.append("request or configured in portal.properties by the"); sb.append("properties "); sb.append("\"portal.instance.http.inet.socket.address\" and "); sb.append("\"portal.instance.https.inet.socket.address\"."); throw new Exception(sb.toString()); } InetAddress inetAddress = inetSocketAddress.getAddress(); String fileName = PortalUtil.getPathContext(); if (!fileName.endsWith(StringPool.SLASH)) { fileName = fileName.concat(StringPool.SLASH); } fileName = fileName.concat("lucene/dump"); URL url = new URL(_protocol, inetAddress.getHostAddress(), inetSocketAddress.getPort(), fileName); String transientToken = (String) clusterNodeResponse.getResult(); return new ObjectValuePair<String, URL>(transientToken, url); } catch (Exception e) { throw new SystemException(e); } }
@Override public FutureClusterResponses execute(ClusterRequest clusterRequest) { if (!isEnabled()) { return null; } List<Address> addresses = prepareAddresses(clusterRequest); Set<String> clusterNodeIds = new HashSet<>(); for (Address address : addresses) { ClusterNode clusterNode = _liveInstances.get(address); if (clusterNode != null) { clusterNodeIds.add(clusterNode.getClusterNodeId()); } } FutureClusterResponses futureClusterResponses = new FutureClusterResponses(clusterNodeIds); if (!clusterRequest.isFireAndForget()) { String uuid = clusterRequest.getUuid(); _futureClusterResponses.put(uuid, futureClusterResponses); } if (addresses.remove(_localAddress)) { ClusterNodeResponse clusterNodeResponse = executeClusterRequest(clusterRequest); if (!clusterRequest.isFireAndForget()) { futureClusterResponses.addClusterNodeResponse(clusterNodeResponse); } } if (clusterRequest.isMulticast()) { try { _controlJChannel.send(null, clusterRequest); } catch (Exception e) { throw new SystemException("Unable to send multicast request", e); } } else { for (Address address : addresses) { org.jgroups.Address jGroupsAddress = (org.jgroups.Address) address.getRealAddress(); try { _controlJChannel.send(jGroupsAddress, clusterRequest); } catch (Exception e) { throw new SystemException("Unable to send unicast request", e); } } } return futureClusterResponses; }
@Override public void execute( ClusterRequest clusterRequest, ClusterResponseCallback clusterResponseCallback) { FutureClusterResponses futureClusterResponses = execute(clusterRequest); try { clusterResponseCallback.callback(futureClusterResponses.get()); } catch (InterruptedException ie) { } }
@Override public void execute( ClusterRequest clusterRequest, ClusterResponseCallback clusterResponseCallback, long timeout, TimeUnit timeUnit) { FutureClusterResponses futureClusterResponses = execute(clusterRequest); try { clusterResponseCallback.callback(futureClusterResponses.get(timeout, timeUnit)); } catch (Exception e) { } }
public static <T> T manageSync(ClusterNode clusterNode, ManageAction<T> manageAction) throws Exception { ClusterGroup clusterGroup = ClusterGroupLocalServiceUtil.createClusterGroup(0); clusterGroup.setClusterNodeIds(clusterNode.getClusterNodeId()); FutureClusterResponses futureClusterResponses = manage(clusterGroup, manageAction); ClusterNodeResponses clusterNodeResponses = futureClusterResponses.get(); ClusterNodeResponse clusterNodeResponse = clusterNodeResponses.getClusterResponse(clusterNode); return (T) clusterNodeResponse.getResult(); }
public static Map<String, String> getClusterServerInfo(String clusterNodeId) throws Exception { List<ClusterNode> clusterNodes = ClusterExecutorUtil.getClusterNodes(); ClusterNode clusterNode = null; for (ClusterNode curClusterNode : clusterNodes) { String curClusterNodeId = curClusterNode.getClusterNodeId(); if (curClusterNodeId.equals(clusterNodeId)) { clusterNode = curClusterNode; break; } } if (clusterNode == null) { return null; } try { if (clusterNode.equals(ClusterExecutorUtil.getLocalClusterNode())) { return getServerInfo(); } ClusterRequest clusterRequest = ClusterRequest.createUnicastRequest(_getServerInfoMethodHandler, clusterNodeId); FutureClusterResponses futureClusterResponses = ClusterExecutorUtil.execute(clusterRequest); ClusterNodeResponses clusterNodeResponses = futureClusterResponses.get(20000, TimeUnit.MILLISECONDS); ClusterNodeResponse clusterNodeResponse = clusterNodeResponses.getClusterResponse(clusterNode); return (Map<String, String>) clusterNodeResponse.getResult(); } catch (Exception e) { _log.error(e, e); throw e; } }
@Override public FutureClusterResponses execute(ClusterRequest clusterRequest) { List<Address> addresses = new ArrayList<Address>(); Collection<Address> clusterNodeAddresses = clusterRequest.getTargetClusterNodeAddresses(); if (clusterNodeAddresses != null) { addresses.addAll(clusterNodeAddresses); } FutureClusterResponses futureClusterResponses = new FutureClusterResponses(addresses); for (Address address : addresses) { ClusterNodeResponse clusterNodeResponse = new ClusterNodeResponse(); clusterNodeResponse.setAddress(address); clusterNodeResponse.setClusterMessageType(ClusterMessageType.EXECUTE); clusterNodeResponse.setMulticast(clusterRequest.isMulticast()); clusterNodeResponse.setUuid(clusterRequest.getUuid()); MockAddress mockAddress = (MockAddress) address.getRealAddress(); try { clusterNodeResponse.setClusterNode( new ClusterNode( String.valueOf(mockAddress.getTimestamp()), InetAddress.getLocalHost())); clusterNodeResponse.setResult(_invoke(clusterRequest.getMethodHandler())); } catch (Exception e) { } futureClusterResponses.addClusterNodeResponse(clusterNodeResponse); } return futureClusterResponses; }