001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 */
019
020package org.nuxeo.runtime.api;
021
022import java.rmi.dgc.VMID;
023
024/**
025 * Provides a way to identify a Nuxeo Runtime instance.
026 * <p>
027 * Identifier can be:
028 * <p>
029 * <ul>
030 * <li>automatically generated (default) based on a {@link VMID}
031 * <li>explicitly set as a system property (org.nuxeo.runtime.instance.id)
032 * </ul>
033 *
034 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a>
035 */
036public class RuntimeInstanceIdentifier {
037
038    protected static final VMID vmid = new VMID();
039
040    protected static String id;
041
042    public static final String INSTANCE_ID_PROPERTY_NAME = "org.nuxeo.runtime.instance.id";
043
044    private RuntimeInstanceIdentifier() {
045    }
046
047    public static String getId() {
048        if (id == null) {
049            id = Framework.getProperty(INSTANCE_ID_PROPERTY_NAME, getVmid().toString());
050        }
051        return id;
052    }
053
054    public static VMID getVmid() {
055        return vmid;
056    }
057
058}