/*
 *    ALMA - Atacama Large Millimiter Array
 *    (c) European Southern Observatory, 2009
 *    Copyright by ESO (in the framework of the ALMA collaboration),
 *    All rights reserved
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *    MA 02111-1307  USA
 */
package alma.acs.alarmsystem.acsimpl;

import java.util.logging.Logger;

import alma.acs.logging.AcsLogLevel;
import alma.alarmsystem.AlarmServicePOA;
import alma.acs.alarmsystem.corbaservice.AlarmSystemCorbaServer;

public class AcsAlarmSystem extends AlarmServicePOA {
	
	/**
	 * The CORBA server
	 */
	private final AlarmSystemCorbaServer corbaServer;
	
	/**
	 * Set to <code>true</code> if the alarm service has been shut down
	 */
	private volatile boolean closed=false;
	
	/**
	 * The logger
	 */
	private final Logger logger;
	
	/**
	 * A class to terminate the alarm service asynchronously.
	 * <P>
	 * The alarm service is stopped by calling the shutdown IDL method.
	 * But inside such a method, the ORB can't be closed.
	 * This class shuts down the servant outside of the ORB thread.
	 * 
	 * @author acaproni
	 *
	 */
	public class AcsComponentTerminator implements Runnable {
		public void run() {
			corbaServer.shutdown();
			logger.log(AcsLogLevel.DEBUG,"See you soon :-)");
			
		}
	}
	
	/**
	 * Constructor
	 */
	public AcsAlarmSystem(AlarmSystemCorbaServer corbaServer) throws Exception {
		if (corbaServer==null) {
			throw new Exception("The CORBA server can't be null");
		}
		this.corbaServer=corbaServer;
		logger=corbaServer.getLogger();
	}
	
	/**
	 * Return the type of alarm system
	 * 
	 * @return always <code>true</code>
	 */
	public boolean isACSAlarmService() {
		return true;
	}
	
	/**
	 * Shutdown the alarm service
	 */
	public synchronized void shutdown() {
		if (closed) {
			return;
		}
		closed=true;
		logger.log(AcsLogLevel.DEBUG,"Shutting down");
		Thread t = new Thread(new AcsComponentTerminator(),"LaserComponentTerminator");
		t.start();
	}
}

@@ -1114,16 +1114,49 @@
 icePOA;%0A
+import alma.alarmsystem.Triplet;%0A
 import a
@@ -1213,16 +1213,196 @@
 erver;%0A%0A
+import alma.acs.util.XmlNormalizer;%0A%0Aimport org.omg.CosPropertyService.Property;%0A%0Aimport alma.ACSErrTypeCommon.BadParameterEx;%0Aimport alma.ACSErrTypeCommon.UnexpectedExceptionEx;%0A%0A
 public c
@@ -2864,10 +2864,969 @@
 t();%0A%09%7D%0A
+%09%0A%09/**%0A%09 * IDL method: submit an alarm without.%0A%09 * %3CP%3E%0A%09 * Build a message to sent to the %7B@link AlarmMessageProcessorImpl#process(Message)%7D.%0A%09 * %0A%09 * @param triplet The triplet of the alarm%0A%09 * @param active if %3Ccode%3Etrue%3C/code%3E the alarm is active%0A%09 * @param sourceHostName The name of the host of the source%0A%09 * @param timestamp The timestamp of the source%0A%09 * @param alarmProperties Additional user-defined properties of the alarm%0A%09 */%0A%09public synchronized void submitAlarm(%0A%09%09%09Triplet triplet,%0A%09%09%09boolean active,%0A%09%09%09String sourceHostName,%0A%09%09%09String sourceName,%0A%09%09%09long timestamp,%0A%09%09%09Property%5B%5D alarmProperties) throws BadParameterEx, UnexpectedExceptionEx %7B%0A%09%09String activeString=active?%22ACTIVE%22:%22TERMINATE%22;%0A%09%09StringBuilder sb = new StringBuilder(%22Alarm sent: %3C%22);%0A%09%09sb.append(triplet.faultFamily+','+triplet.faultMember+','+triplet.faultCode+%22%3E %22);%0A%09%09sb.append(activeString);%0A%09%09logger.log(AcsLogLevel.ALERT,XmlNormalizer.normalize(sb.toString()));%0A%09%7D%0A
 %7D%0A

Implement submitAlarm(...)