From be6f2734a8ba7d934a4af259a8006134d98d3439 Mon Sep 17 00:00:00 2001 From: Steve Millidge Date: Mon, 27 Feb 2017 22:24:12 +0000 Subject: [PATCH 1/3] PAYARA-1487 first cut of the integration --- .../micro/services/PayaraInstanceImpl.java | 4 +- .../nucleus/exec/ClusterExecutionService.java | 271 +++++++++++++++--- .../nucleus/exec/ScheduledTaskFuture.java | 61 ++++ .../nucleus/hazelcast/HazelcastCore.java | 17 +- .../HazelcastRuntimeConfiguration.java | 15 + .../nucleus/hazelcast/NameGenerator.java | 37 ++- 6 files changed, 356 insertions(+), 49 deletions(-) create mode 100644 nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java diff --git a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java index 71f98a8d6a5..9f6c06b41e8 100644 --- a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java +++ b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java @@ -130,7 +130,7 @@ public Map> runCallable(Collection Map> runCallable(Callable callable) { - return cluster.getExecService().runCallable(callable); + return cluster.getExecService().runCallableAllMembers(callable); } @Override @@ -141,7 +141,7 @@ public ClusterCommandResult executeLocalAsAdmin(String command, String... parame @Override public Map> executeClusteredASAdmin(String command, String... parameters) { AsAdminCallable callable = new AsAdminCallable(command, parameters); - Map> result = cluster.getExecService().runCallable(callable); + Map> result = cluster.getExecService().runCallableAllMembers(callable); return result; } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java index 3568eac5268..d14f09f7a31 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java @@ -1,24 +1,48 @@ /* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 Payara Foundation. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. */ package fish.payara.nucleus.exec; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.core.Member; +import com.hazelcast.scheduledexecutor.IScheduledExecutorService; +import com.hazelcast.scheduledexecutor.IScheduledFuture; import fish.payara.nucleus.events.HazelcastEvents; import fish.payara.nucleus.hazelcast.HazelcastCore; import java.io.Serializable; @@ -29,6 +53,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import javax.annotation.PostConstruct; import javax.inject.Inject; @@ -39,7 +64,8 @@ and Distribution License("CDDL") (collectively, the "License"). You import org.jvnet.hk2.annotations.Service; /** - * A Hazelcast based Event Bus for Payara + * Execution Service for running Callables across the Payara Cluster also enables + * Scheduling of Callables to run on the cluster. * @author steve */ @Service(name = "payara-cluster-executor") @@ -47,7 +73,7 @@ and Distribution License("CDDL") (collectively, the "License"). You public class ClusterExecutionService implements EventListener { private static final Logger logger = Logger.getLogger(ClusterExecutionService.class.getCanonicalName()); - + @Inject private HazelcastCore hzCore; @@ -59,36 +85,49 @@ public void postConstruct() { events.register(this); } + /** + * Runs a Callable object + * @param Type of the Callable Result + * @param callable The Callable object + * @return Future for the result + */ + public Future runCallable(Callable callable) { + Future result = null; + if (hzCore.isEnabled()) { + result = hzCore.getInstance().getExecutorService(HazelcastCore.CLUSTER_EXECUTOR_SERVICE_NAME).submit(callable); + } + return result; + } + + /** + * Runs a Callable object on the specified Member + * @param Type of the Callable Result + * @param memberUUID The member to run the Callable on + * @param callable The Callable object + * @return Future for the result + */ public Future runCallable(String memberUUID, Callable callable) { Future result = null; if (hzCore.isEnabled()) { - HazelcastInstance instance = hzCore.getInstance(); - Set members = instance.getCluster().getMembers(); - Member toSubmitTo = null; - for (Member member : members) { - if (member.getUuid().equals(memberUUID)) { - toSubmitTo = member; - break; - } - } - result = instance.getExecutorService("payara-cluster-execution").submitToMember(callable, toSubmitTo); + Member toSubmitTo = selectMember(memberUUID); + result = hzCore.getInstance().getExecutorService(HazelcastCore.CLUSTER_EXECUTOR_SERVICE_NAME).submitToMember(callable, toSubmitTo); } return result; } + /** + * Runs a Callable object on a set of members + * @param The type of the Callable result + * @param memberUUIDS A set of members to run the Callables on + * @param callable The Callable to run + * @return A map of Futures keyed by Member UUID + */ public Map> runCallable(Collection memberUUIDS, Callable callable) { HashMap> result = new HashMap>(2); if (hzCore.isEnabled()) { - // work out which members correspond to cluster UUIDS. - HazelcastInstance instance = hzCore.getInstance(); - Set members = instance.getCluster().getMembers(); - Set membersToSubmit = new HashSet(members.size()); - for (Member member : members) { - if (memberUUIDS.contains(member.getUuid())) { - membersToSubmit.add(member); - } - } - Map> results = hzCore.getInstance().getExecutorService("payara-cluster-execution").submitToMembers(callable, membersToSubmit); + + Set membersToSubmit = selectMembers(memberUUIDS); + Map> results = hzCore.getInstance().getExecutorService(HazelcastCore.CLUSTER_EXECUTOR_SERVICE_NAME).submitToMembers(callable, membersToSubmit); for (Member member : results.keySet()) { result.put(member.getUuid(), results.get(member)); } @@ -96,18 +135,148 @@ public Map> runCallable(Collection Map> runCallable(Callable callable) { + /** + * Runs a Callable on All members of the cluster + * @param The result of the Callable + * @param callable The Callable to run + * @return A Map of Future results keyed by member UUID + */ + public Map> runCallableAllMembers(Callable callable) { HashMap> result = new HashMap>(2); if (hzCore.isEnabled()) { // work out which members correspond to cluster UUIDS. HazelcastInstance instance = hzCore.getInstance(); - Map> results = hzCore.getInstance().getExecutorService("payara-cluster-execution").submitToAllMembers(callable); + Map> results = hzCore.getInstance().getExecutorService(HazelcastCore.CLUSTER_EXECUTOR_SERVICE_NAME).submitToAllMembers(callable); for (Member member : results.keySet()) { result.put(member.getUuid(), results.get(member)); } } return result; } + + /** + * Schedules a Callable object to be run in the future + * @param The type of the result + * @param callable The Callable Object + * @param delay The delay before running the task + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public ScheduledTaskFuture schedule(Callable callable, long delay, TimeUnit unit) { + ScheduledTaskFuture result = null; + if (hzCore.isEnabled()) { + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + IScheduledFuture schedule = scheduledExecutorService.schedule(callable, delay, unit); + result = new ScheduledTaskFuture(schedule); + } + return result; + } + + /** + * Schedules a Callable object to be run in the future on the specified Member + * @param The type of the result + * @param memberUUID The member to schedule the task on + * @param callable The Callable Object + * @param delay The delay before running the task + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public ScheduledTaskFuture schedule(String memberUUID, Callable callable, long delay, TimeUnit unit) { + ScheduledTaskFuture result = null; + + if (hzCore.isEnabled()) { + Member toSubmitTo = selectMember(memberUUID); + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + IScheduledFuture schedule = scheduledExecutorService.scheduleOnMember(callable, toSubmitTo, delay, unit); + result = new ScheduledTaskFuture(schedule); + } + return result; + } + + /** + * Schedules a Callable object to be run in the future on the specified Member + * @param The type of the result + * @param memberUUIDs The members to schedule the task on + * @param callable The Callable Object + * @param delay The delay before running the task + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public Map> schedule(Collection memberUUIDs, Callable callable, long delay, TimeUnit unit) { + HashMap> result = new HashMap<>(2); + + if (hzCore.isEnabled()) { + Collection toSubmitTo = selectMembers(memberUUIDs); + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + Map> schedule = scheduledExecutorService.scheduleOnMembers(callable, toSubmitTo, delay, unit); + for (Member member : schedule.keySet()) { + result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member))); + } + } + return result; + } + + /** + * Schedules a Callable object to be run in the future + * @param runnable The Runnable Object + * @param delay The delay before running the task + * @param periodThe period for the fixed rate + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public ScheduledTaskFuture scheduleAtFixedRate(Runnable runnable, long delay, long period, TimeUnit unit) { + ScheduledTaskFuture result = null; + if (hzCore.isEnabled()) { + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + IScheduledFuture schedule = scheduledExecutorService.scheduleAtFixedRate(runnable, delay, period, unit); + result = new ScheduledTaskFuture(schedule); + } + return result; + } + + /** + * Schedules a Callable object to be run in the future on the specified Member + * @param memberUUID The member to schedule the task on + * @param runnable The Runnable Object + * @param delay The delay before running the task + * @param period The period for the fixed rate + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public ScheduledTaskFuture scheduleAtFixedRate(String memberUUID, Runnable runnable, long delay, long period, TimeUnit unit) { + ScheduledTaskFuture result = null; + + if (hzCore.isEnabled()) { + Member toSubmitTo = selectMember(memberUUID); + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + IScheduledFuture schedule = scheduledExecutorService.scheduleOnMemberAtFixedRate(runnable, toSubmitTo, delay, period, unit); + result = new ScheduledTaskFuture(schedule); + } + return result; + } + + /** + * Schedules a Callable object to be run in the future on the specified Member + * @param memberUUIDs The members to schedule the task on + * @param runnable The Runnable Object + * @param delay The delay before running the task + * @param period The period of the fixed rate + * @param unit The time unit of the delay + * @return A Future containing the result + */ + public Map> scheduleAtFixedRate(Collection memberUUIDs, Runnable runnable, long delay, long period, TimeUnit unit) { + HashMap> result = new HashMap<>(2); + + if (hzCore.isEnabled()) { + Collection toSubmitTo = selectMembers(memberUUIDs); + IScheduledExecutorService scheduledExecutorService = hzCore.getInstance().getScheduledExecutorService(HazelcastCore.SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + Map> schedule = scheduledExecutorService.scheduleOnMembersAtFixedRate(runnable, toSubmitTo, delay, period, unit); + for (Member member : schedule.keySet()) { + result.put(member.getUuid(), new ScheduledTaskFuture<>(schedule.get(member))); + } + } + return result; + } @Override public void event(Event event) { @@ -118,6 +287,30 @@ public void event(Event event) { } } + private Member selectMember(String memberUUID) { + Set members = hzCore.getInstance().getCluster().getMembers(); + Member toSubmitTo = null; + for (Member member : members) { + if (member.getUuid().equals(memberUUID)) { + toSubmitTo = member; + break; + } + } + return toSubmitTo; + } + + private Set selectMembers(Collection memberUUIDS) { + // work out which members correspond to cluster UUIDS. + HazelcastInstance instance = hzCore.getInstance(); + Set members = instance.getCluster().getMembers(); + Set membersToSubmit = new HashSet(members.size()); + for (Member member : members) { + if (memberUUIDS.contains(member.getUuid())) { + membersToSubmit.add(member); + } + } + return membersToSubmit; + } } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java new file mode 100644 index 00000000000..e3e82c06e83 --- /dev/null +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java @@ -0,0 +1,61 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package fish.payara.nucleus.exec; + +import com.hazelcast.scheduledexecutor.IScheduledFuture; +import java.util.concurrent.Delayed; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * + * @author Steve Millidge + * @param Type of the object + */ +public class ScheduledTaskFuture implements Future { + + private IScheduledFuture wrappee; + + public ScheduledTaskFuture(IScheduledFuture future) { + wrappee = future; + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return wrappee.cancel(mayInterruptIfRunning); + } + + @Override + public boolean isCancelled() { + return wrappee.isCancelled(); + } + + @Override + public boolean isDone() { + return wrappee.isDone(); + } + + @Override + public Object get() throws InterruptedException, ExecutionException { + Object result = wrappee.get(); + // as we got the result dispose of the IScheduledFuture + wrappee.dispose(); + return result; + } + + @Override + public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + Object result = wrappee.get(); + // as we got the result dispose of the IScheduledFuture + wrappee.dispose(); + return result; + } + + + +} diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java index d447f3ddbfa..ef71b91fa69 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java @@ -45,10 +45,12 @@ import com.hazelcast.config.Config; import com.hazelcast.config.ConfigLoader; import com.hazelcast.config.GlobalSerializerConfig; +import com.hazelcast.config.SerializationConfig; +import com.hazelcast.config.ExecutorConfig; import com.hazelcast.config.GroupConfig; import com.hazelcast.config.MulticastConfig; import com.hazelcast.config.PartitionGroupConfig; -import com.hazelcast.config.SerializationConfig; +import com.hazelcast.config.ScheduledExecutorConfig; import com.hazelcast.core.Hazelcast; import com.hazelcast.core.HazelcastInstance; import com.hazelcast.nio.serialization.Serializer; @@ -91,6 +93,8 @@ public class HazelcastCore implements EventListener { public final static String INSTANCE_ATTRIBUTE = "GLASSFISH-INSTANCE"; public final static String INSTANCE_GROUP_ATTRIBUTE = "GLASSFISH_INSTANCE_GROUP"; + public static final String CLUSTER_EXECUTOR_SERVICE_NAME="payara-cluster-execution"; + public static final String SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME="payara-scheduled-execution"; private static HazelcastCore theCore; private HazelcastInstance theInstance; @@ -267,6 +271,17 @@ private Config buildConfiguration() { partitionGroupConfig.setEnabled(enabled); partitionGroupConfig.setGroupType(PartitionGroupConfig.MemberGroupType.HOST_AWARE); } + + // build the executor config + ExecutorConfig executorConfig = config.getExecutorConfig(CLUSTER_EXECUTOR_SERVICE_NAME); + executorConfig.setStatisticsEnabled(true); + executorConfig.setPoolSize(Integer.valueOf(configuration.getExecutorPoolSize())); + executorConfig.setQueueCapacity(Integer.valueOf(configuration.getExecutorQueueCapacity())); + + ScheduledExecutorConfig scheduledExecutorConfig = config.getScheduledExecutorConfig(SCHEDULED_CLUSTER_EXECUTOR_SERVICE_NAME); + scheduledExecutorConfig.setDurability(1); + scheduledExecutorConfig.setCapacity(Integer.valueOf(configuration.getScheduledExecutorQueueCapacity())); + scheduledExecutorConfig.setPoolSize(Integer.valueOf(configuration.getScheduledExecutorPoolSize())); config.setProperty("hazelcast.jmx", "true"); } diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java index f8d51d615cc..143b2baddf9 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java @@ -89,7 +89,22 @@ public interface HazelcastRuntimeConfiguration String getHostAwarePartitioning(); public void setHostAwarePartitioning(String value); + @Attribute(defaultValue = "4") + String getExecutorPoolSize(); + public void setExecutorPoolSize(String value); + @Attribute(defaultValue = "20") + String getExecutorQueueCapacity(); + public void setExecutorQueueCapacity(String value); + + @Attribute(defaultValue = "4") + String getScheduledExecutorPoolSize(); + public void setScheduledExecutorPoolSize(String value); + + @Attribute(defaultValue = "20") + String getScheduledExecutorQueueCapacity(); + public void setScheduledExecutorQueueCapacity(String value); + @Attribute(defaultValue = "") String getLicenseKey(); public void setLicenseKey(String value); diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/NameGenerator.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/NameGenerator.java index 1509af51e5d..b28026256e1 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/NameGenerator.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/NameGenerator.java @@ -1,18 +1,41 @@ -/** +/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. * - * The contents of this file are subject to the terms of the Common Development + * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You * may not use this file except in compliance with the License. You can * obtain a copy of the License at - * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - * or packager/legal/LICENSE.txt. See the License for the specific + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific * language governing permissions and limitations under the License. * * When distributing the software, include this License Header Notice in each - * file and include the License file at packager/legal/LICENSE.txt. + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. */ package fish.payara.nucleus.hazelcast; From 401395eb47b0fe4b1e85e70395d1928a27054de7 Mon Sep 17 00:00:00 2001 From: Steve Millidge Date: Mon, 27 Feb 2017 22:52:25 +0000 Subject: [PATCH 2/3] PAYARA-1487 minor clean up of some HZ code --- .../fish/payara/micro/PayaraMicroRuntime.java | 7 +- .../nucleus/exec/ClusterExecutionService.java | 8 +- .../nucleus/hazelcast/HazelcastCore.java | 2 +- .../HazelcastRuntimeConfiguration.java | 2 +- .../hazelcast/MulticastConfiguration.java | 130 ------------------ 5 files changed, 7 insertions(+), 142 deletions(-) delete mode 100644 nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/MulticastConfiguration.java diff --git a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraMicroRuntime.java b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraMicroRuntime.java index 3d8fe017c6c..687bff26b10 100644 --- a/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraMicroRuntime.java +++ b/appserver/extras/payara-micro/payara-micro-boot/src/main/java/fish/payara/micro/PayaraMicroRuntime.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2016 Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) 2016-2017 Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -39,11 +39,6 @@ */ package fish.payara.micro; -//import fish.payara.appserver.micro.services.CDIEventListener; -//import fish.payara.appserver.micro.services.PayaraClusterListener; -//import fish.payara.appserver.micro.services.PayaraClusteredCDIEvent; -//import fish.payara.appserver.micro.services.command.ClusterCommandResult; -//import fish.payara.appserver.micro.services.data.InstanceDescriptor; import fish.payara.micro.event.PayaraClusteredCDIEvent; import fish.payara.micro.event.PayaraClusterListener; import fish.payara.micro.event.CDIEventListener; diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java index d14f09f7a31..f580173d189 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ClusterExecutionService.java @@ -123,7 +123,7 @@ public Future runCallable(String memberUUID, Callabl * @return A map of Futures keyed by Member UUID */ public Map> runCallable(Collection memberUUIDS, Callable callable) { - HashMap> result = new HashMap>(2); + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { Set membersToSubmit = selectMembers(memberUUIDS); @@ -142,7 +142,7 @@ public Map> runCallable(Collection Map> runCallableAllMembers(Callable callable) { - HashMap> result = new HashMap>(2); + HashMap> result = new HashMap<>(2); if (hzCore.isEnabled()) { // work out which members correspond to cluster UUIDS. HazelcastInstance instance = hzCore.getInstance(); @@ -220,7 +220,7 @@ public Map> schedule(Col * Schedules a Callable object to be run in the future * @param runnable The Runnable Object * @param delay The delay before running the task - * @param periodThe period for the fixed rate + * @param period The period for the fixed rate * @param unit The time unit of the delay * @return A Future containing the result */ @@ -303,7 +303,7 @@ private Set selectMembers(Collection memberUUIDS) { // work out which members correspond to cluster UUIDS. HazelcastInstance instance = hzCore.getInstance(); Set members = instance.getCluster().getMembers(); - Set membersToSubmit = new HashSet(members.size()); + Set membersToSubmit = new HashSet<>(members.size()); for (Member member : members) { if (memberUUIDS.contains(member.getUuid())) { membersToSubmit.add(member); diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java index ef71b91fa69..178cdb33139 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastCore.java @@ -85,7 +85,7 @@ /** * - * @author steve + * @author Steve Millidge (Payara Foundation) */ @Service(name = "hazelcast-core") @RunLevel(StartupRunLevel.VAL) diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java index 143b2baddf9..e938c261714 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/HazelcastRuntimeConfiguration.java @@ -24,7 +24,7 @@ and Distribution License("CDDL") (collectively, the "License"). You /** * - * @author steve + * @author Steve Millidge (Payara Foundation) */ @Configured public interface HazelcastRuntimeConfiguration diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/MulticastConfiguration.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/MulticastConfiguration.java deleted file mode 100644 index 404dc80ec49..00000000000 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/hazelcast/MulticastConfiguration.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - - Copyright (c) 2016 Payara Foundation. All rights reserved. - - The contents of this file are subject to the terms of the Common Development - and Distribution License("CDDL") (collectively, the "License"). You - may not use this file except in compliance with the License. You can - obtain a copy of the License at - https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html - or packager/legal/LICENSE.txt. See the License for the specific - language governing permissions and limitations under the License. - - When distributing the software, include this License Header Notice in each - file and include the License file at packager/legal/LICENSE.txt. - */ -package fish.payara.nucleus.hazelcast; - -import java.net.URI; - -/** - * - * @author steve - */ -public class MulticastConfiguration { - private String multicastGroup = "224.2.2.3"; - private int multicastPort = 54327; - private int startPort = 5900; - private String memberName; - private URI alternateConfigFile; - private boolean lite = false; - private String clusterGroupName = "development"; - private String clusterGroupPassword = "D3v3l0pm3nt"; - private String licenseKey; - private String memberGroup; - - public MulticastConfiguration() { - } - - public MulticastConfiguration(String multicastGroup, int multicastPort, int startPort, String memberName, String memberGroup, URI alternateConfigurationFile, String licenseKey) { - this.multicastGroup = multicastGroup; - this.multicastPort = multicastPort; - this.startPort = startPort; - this.memberName = memberName; - this.memberGroup = memberGroup; - this.alternateConfigFile = alternateConfigurationFile; - this.licenseKey = licenseKey; - } - - public void setMulticastGroup(String multicastGroup) { - this.multicastGroup = multicastGroup; - } - - public String getMulticastGroup() { - return multicastGroup; - } - - public void setMulticastPort(int multicastPort) { - this.multicastPort = multicastPort; - } - - public int getMulticastPort() { - return multicastPort; - } - - public void setStartPort(int startPort) { - this.startPort = startPort; - } - - public int getStartPort() { - return startPort; - } - - public String getMemberName() { - return memberName; - } - - public void setMemberName(String memberName) { - this.memberName = memberName; - } - - public void setAlternateConfiguration(URI alternateHZConfigFile) { - alternateConfigFile = alternateHZConfigFile; - } - - public URI getAlternateConfigFile() { - return alternateConfigFile; - } - - public void setLicenseKey(String licenseKey) { - this.licenseKey = licenseKey; - } - - public String getLicenseKey() { - return licenseKey; - } - - public boolean isLite() { - return lite; - } - - public void setLite(boolean lite) { - this.lite = lite; - } - - public String getClusterGroupName() { - return clusterGroupName; - } - - public void setClusterGroupName(String clusterGroupName) { - this.clusterGroupName = clusterGroupName; - } - - public String getClusterGroupPassword() { - return clusterGroupPassword; - } - - public void setClusterGroupPassword(String clusterGroupPassword) { - this.clusterGroupPassword = clusterGroupPassword; - } - - public String getMemberGroup() { - return memberGroup; - } - - public void setMemberGroup(String memberGroup) { - this.memberGroup = memberGroup; - } -} From b341b520af06466c39a140d8d6365f2baa23e748 Mon Sep 17 00:00:00 2001 From: Steve Millidge Date: Sat, 22 Apr 2017 20:51:25 +0100 Subject: [PATCH 3/3] PAYARA-1487 Minor clean up. Scheduled Executor is now enabled in the internal ClusterExecutionService --- .../cdi/extension/PayaraMicroProducer.java | 15 +++++-- .../micro/services/PayaraInstanceImpl.java | 7 +++- .../nucleus/exec/ScheduledTaskFuture.java | 41 +++++++++++++++++-- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/PayaraMicroProducer.java b/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/PayaraMicroProducer.java index 339e0d5b9eb..412f267cc70 100644 --- a/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/PayaraMicroProducer.java +++ b/appserver/payara-appserver-modules/payara-micro-cdi/src/main/java/fish/payara/micro/cdi/extension/PayaraMicroProducer.java @@ -40,6 +40,8 @@ package fish.payara.micro.cdi.extension; import fish.payara.micro.PayaraInstance; +import fish.payara.micro.PayaraMicro; +import fish.payara.micro.PayaraMicroRuntime; import javax.enterprise.inject.Produces; import org.glassfish.internal.api.Globals; @@ -49,14 +51,19 @@ */ public class PayaraMicroProducer { - private final PayaraInstance runtime; + private final PayaraInstance instance; PayaraMicroProducer() { - runtime = Globals.getDefaultHabitat().getService(PayaraInstance.class); + instance = Globals.getDefaultHabitat().getService(PayaraInstance.class); } @Produces - PayaraInstance getRuntime() { - return runtime; + public PayaraInstance getInstance() { + return instance; + } + + @Produces + public PayaraMicroRuntime getRuntime() { + return PayaraMicro.getInstance().getRuntime(); } } diff --git a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java index 9f6c06b41e8..be0b6d4db29 100644 --- a/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java +++ b/appserver/payara-appserver-modules/payara-micro-service/src/main/java/fish/payara/appserver/micro/services/PayaraInstanceImpl.java @@ -44,6 +44,7 @@ and Distribution License("CDDL") (collectively, the "License"). You import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; @@ -122,6 +123,8 @@ public void setInstanceName(String instanceName) { this.instanceName = instanceName; me.setInstanceName(instanceName); } + + @Override public Map> runCallable(Collection memberUUIDS, Callable callable) { @@ -141,7 +144,7 @@ public ClusterCommandResult executeLocalAsAdmin(String command, String... parame @Override public Map> executeClusteredASAdmin(String command, String... parameters) { AsAdminCallable callable = new AsAdminCallable(command, parameters); - Map> result = cluster.getExecService().runCallableAllMembers(callable); + Map> result = cluster.getExecService().runCallableAllMembers(callable); return result; } @@ -187,7 +190,7 @@ void postConstruct() { events.register(this); myListeners = new HashSet<>(1); myCDIListeners = new HashSet<>(1); - initialiseInstanceDescriptor(); + initialiseInstanceDescriptor(); } /** diff --git a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java index e3e82c06e83..891aa24c20b 100644 --- a/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java +++ b/nucleus/payara-modules/hazelcast-bootstrap/src/main/java/fish/payara/nucleus/exec/ScheduledTaskFuture.java @@ -1,12 +1,45 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) [2016-2017] Payara Foundation and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://github.com/payara/Payara/blob/master/LICENSE.txt + * See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at glassfish/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * The Payara Foundation designates this particular file as subject to the "Classpath" + * exception as provided by the Payara Foundation in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. */ package fish.payara.nucleus.exec; import com.hazelcast.scheduledexecutor.IScheduledFuture; -import java.util.concurrent.Delayed; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit;