/************************************************
* Columbia University CS Department
* Network Security Lab
*
* Open and Survivable Embedded Systems (OASES)
*
* Structured Policy Command Language (SPCL)
*
*
* This software is provided as is without any
* warranty or guarantee of merchantibility
* or fitness for a particular purpose. This
* software is released under the terms of the
* GNU General Public License (GPL).
*
* Last updated: March 28, 2003
*
***********************************************/

package spcl.policyengine;

import java.util.*;
import java.net.*;
import java.io.*;

public class StopTask{

   public StopTask( String filename ) throws Exception{
     Socket client;
	 ObjectInputStream oin;
	 ObjectOutputStream oout;
     String ipaddr,message;
	 int port;

	 Properties configs = new Properties();
	 configs.load( new FileInputStream( new File( filename ) ) );
	 port = Integer.parseInt( configs.getProperty( "spcl.console.port", "3781" ) );
	 message = configs.getProperty( "spcl.shutdownmessage", "" );
	 configs=null;
	System.out.println( "read config info from "+filename );

	client = new Socket( InetAddress.getLocalHost(), port );
	oout = new ObjectOutputStream( client.getOutputStream() );
	oout.flush();
	oin = new ObjectInputStream( client.getInputStream() );

	System.out.println( "connected to PolicyEngine console..." );

	oout.writeObject( message );
	oout.flush();
	
	System.out.println( "wrote shutdown message..." );

	//oin.close();
	//oout.close();
	//client.close();
	
	System.out.println( "StopTask done." );

   }

}
