/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.shardingsphere.orchestration.core.registrycenter.instance;

import lombok.Getter;
import org.apache.shardingsphere.orchestration.core.registrycenter.util.IpUtils;

import java.lang.management.ManagementFactory;
import java.util.UUID;

/**
 * Orchestration instance.
 */
@Getter
public final class OrchestrationInstance {
    
    private static final String DELIMITER = "@";
    
    private static final OrchestrationInstance INSTANCE = new OrchestrationInstance();
    
    private final String instanceId;
    
    private OrchestrationInstance() {
        instanceId = IpUtils.getIp() + DELIMITER + ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)[0] + DELIMITER + UUID.randomUUID().toString();
    }
    
    /**
     * Get instance.
     * 
     * @return instance
     */
    public static OrchestrationInstance getInstance() {
        return INSTANCE;
    }
}

@@ -983,78 +983,8 @@
 s;%0A%0A
-import java.lang.management.ManagementFactory;%0Aimport java.util.UUID;%0A
 %0A/**
@@ -1120,20 +1120,16 @@
  = %22@%22;%0A
-    
 %0A    pri
@@ -1140,22 +1140,16 @@
  static 
-final 
 Orchestr
@@ -1166,46 +1166,16 @@
 nce 
-INSTANCE = new OrchestrationI
+i
 nstance
-()
 ;%0A  
@@ -1214,32 +1214,27 @@
 anceId;%0A
-    
 %0A    p
-rivate
+ublic
  Orchest
@@ -1240,32 +1240,46 @@
 trationInstance(
+final int port
 ) %7B%0A        inst
@@ -1321,125 +1321,20 @@
 R + 
-ManagementFactory.getRuntimeMXBean().getName().split(DELIMITER)%5B0%5D + DELIMITER + UUID.randomUUID().toString()
+port
 ;%0A    %7D%0A
     
@@ -1329,20 +1329,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**
@@ -1369,127 +1369,473 @@
    *
- %0A     * @return instance%0A     */%0A    public static OrchestrationInstance getInstance() %7B%0A        return INSTANCE;%0A    %7D
+%0A     * @param   port        port on which the instance is running%0A     * @return  instance    the orchestration instance%0A     */%0A    public static OrchestrationInstance getInstance(final int port) %7B%0A        if (null == instance) %7B%0A            synchronized (OrchestrationInstance.class) %7B%0A                if (null == instance) %7B%0A                    instance = new OrchestrationInstance(port);%0A                %7D%0A            %7D%0A        %7D%0A        return instance;%0A    %7D%0A
 %0A%7D%0A

update instance id to consume port info