001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Nuxeo - initial API and implementation 011 */ 012 013package org.nuxeo.runtime.api; 014 015import java.rmi.dgc.VMID; 016 017/** 018 * Provides a way to identify a Nuxeo Runtime instance. 019 * <p> 020 * Identifier can be: 021 * <p> 022 * <ul> 023 * <li>automatically generated (default) based on a {@link VMID} 024 * <li>explicitly set as a system property (org.nuxeo.runtime.instance.id) 025 * </ul> 026 * 027 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 028 */ 029public class RuntimeInstanceIdentifier { 030 031 protected static final VMID vmid = new VMID(); 032 033 protected static String id; 034 035 public static final String INSTANCE_ID_PROPERTY_NAME = "org.nuxeo.runtime.instance.id"; 036 037 private RuntimeInstanceIdentifier() { 038 } 039 040 public static String getId() { 041 if (id == null) { 042 id = Framework.getProperty(INSTANCE_ID_PROPERTY_NAME, getVmid().toString()); 043 } 044 return id; 045 } 046 047 public static VMID getVmid() { 048 return vmid; 049 } 050 051}