/*
 * $Id: VKCServer.java,v 1.6 2007/08/16 11:10:59 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: VKCServer.java,v $
 * Revision 1.6  2007/08/16 11:10:59  marbobo
 * + Bugfixes
 * + Refactorings
 *
 * Revision 1.5  2004/11/19 14:00:33  koppy
 * Kleine Änderungen wegen Converter-Serveränderungen
 *
 */
package vkc.server;

import java.net.Socket;
import java.util.Properties;

import vkc.db.PersistenceManager;
import vkc.db.common.VKCServerInfo;
import vkc.view.WebShare;

/**
 * This class represents the VKCServer which is listening for incoming archive
 * request from converter servers...
 * 
 * @created 07.01.2004
 * @author Andreas Koop
 */
public class VKCServer extends ServerSupport {

    /**
     * Constructs a new VKCServer
     * 
     * @param p
     *            properties
     */
    public VKCServer(Properties p) throws Exception {
        this.conf = new VKCServerInfo();

        String port = p.getProperty("vkc.server.port");

        if (port == null) {
            port = "-1";
        }

        try {
            conf.setPort(Integer.parseInt(port));
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Specified port ('vkc.server.port') must be a numeric value!");
        }
        // Persistence Manager
        PersistenceManager.getInstance().init(WebShare.database);

        // Registers the VKC server in the database
        // if already registered, nothing is done
        VKCServerInfo.register(p);
        conf.initialize(new Integer(p.getProperty("vkc.server.id")));
        
        if (conf.getPort() == -1) {
            throw new IllegalArgumentException("The Converter port ('vkc.server.port') was not set!");
        }
    }

    /**
     * (non-Javadoc)
     * 
     * @see vkc.server.ServerSupport#process(java.net.Socket)
     */
    protected void process(Socket client) throws Exception {
        Thread p = new Thread(new RequestProcessor(this, client));
        p.setPriority(Thread.MIN_PRIORITY);
        p.start();

    }
}