package de.mayring.payarahazelcastexample;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;

import javax.annotation.PostConstruct;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

import fish.payara.micro.PayaraMicro;
import fish.payara.micro.PayaraMicroRuntime;

@ApplicationPath("/")
public class ApplicationConfig extends Application {

    private static final List<String> colors = Arrays.asList(new String[] { "Fuchsia", "Teal", "Lime", "Blue", "Black" }); 

    public ApplicationConfig() {
    }

    static String getColor() {
        return colors.get(ThreadLocalRandom.current().nextInt(0, colors.size()));
    }

    @PostConstruct
    public void configurePayara() {
        final PayaraMicroRuntime pmRuntime = PayaraMicro.getInstance().getRuntime();
        pmRuntime.run("healthcheck-configure", "--enabled=true", "--dynamic=true");
        pmRuntime.run("healthcheck-configure-service", "--serviceName=healthcheck-cpu", "--enabled=true",
            "--time=5", "--unit=SECONDS", "--dynamic=true");
        pmRuntime.run("healthcheck-configure-service-threshold", "--serviceName=healthcheck-cpu",
            "--thresholdCritical=90", "--thresholdWarning=50", "--thresholdGood=0", "--dynamic=true");
        pmRuntime.run("healthcheck-configure-service", "--serviceName=healthcheck-machinemem",
            "--enabled=true", "--dynamic=true", "--time=5","--unit=SECONDS");
        pmRuntime.run("healthcheck-configure-service-threshold", "--serviceName=healthcheck-machinemem",
            "--thresholdCritical=90", "--thresholdWarning=50", "--thresholdGood=0", "--dynamic=true");
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        addRestResourceClasses(resources);
        return resources;
    }

    /**
     * Do not modify addRestResourceClasses() method.
     * It is automatically populated with
     * all resources defined in the project.
     * If required, comment out calling this method in getClasses().
     */
    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(de.mayring.payarahazelcastexample.UuidService.class);
    }
    
}

@@ -58,15 +58,13 @@
 til.
-Arrays;
+Set;%0A
 %0Aimp
@@ -75,127 +75,68 @@
 java
-.util.List;%0Aimport java.util.Set;%0Aimport java.util.concurrent.ThreadLocalRandom;%0A%0Aimport javax.annotation.PostConstruct
+x.naming.InitialContext;%0Aimport javax.naming.NamingException
 ;%0Aim
@@ -291,16 +291,95 @@
 ntime;%0A%0A
+import com.hazelcast.core.HazelcastInstance;%0Aimport com.hazelcast.core.IList;%0A%0A
 @Applica
@@ -462,21 +462,15 @@
 ate 
-static 
 final 
+I
 List
@@ -488,254 +488,433 @@
 lors
- = Arrays.asList(new String%5B%5D %7B %22Fuchsia%22, %22Teal%22, %22Lime%22, %22Blue%22, %22Black%22 %7D); %0A%0A    public ApplicationConfig() %7B
+;%0A%0A    public ApplicationConfig() throws NamingException %7B%0A        javax.naming.Context ctx = new InitialContext();%0A        HazelcastInstance hazelcast = (HazelcastInstance) ctx.lookup(%22payara/Hazelcast%22);%0A        colors = hazelcast.getList(%22colors%22);
 %0A    
-%7D%0A%0A
     
-static String getColor() %7B%0A        return colors.get(ThreadLocalRandom.current().nextInt(0, colors.size()));%0A    %7D%0A%0A    @
+colors.add(%22Fuchsia%22);%0A        colors.add(%22Teal%22);%0A        colors.add(%22Lime%22);%0A        colors.add(%22Blue%22);%0A        colors.add(%22Black%22);%0A    %7D%0A%0A    @javax.annotation.
 Post

initialise colors via Hazelcast