/*
 *  DynObject.java v0.10 28-JAN-2000
 *  Copyright (c) TKK/TLM/Calypso
 *  Author: Alexey Mednonogov
 */

package codec.client;

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

import codec.*;
import codec.adapt.*;
import codec.convert.*;
import codec.debug.*;
import codec.dyntree.*;
import codec.export.*;
import codec.orb.*;
import codec.pco.*;
import codec.server.*;
import codec.client.*;
import codec.visit.*;
import codec.build.*;

/** Class implementing Universal Servant for accepting Client requests. */
public final class DynObject extends org.omg.CORBA.DynamicImplementation {

	private String[] ids;
	public String[] _ids() { return ids; }

	/* Defines type of registration of this servant. */
	public int refType;
	public static final int REF_TYPE_RFILE = 0;
	public static final int REF_TYPE_NSERV = 1;

	/* If (refType == REF_TYPE_RFILE), contains location of IOR file. */
	public String refFile;

	/* If (refType == REF_TYPE_NSERV), contains location in Naming Service. */
	public String[] nsLocation;

    /** Defines whether an exceptional situation happened during invocation
     *  which requires to immediately raise CORBA::UNKNOWN exception for
     *  all requests associated with this object. */
	public volatile Boolean isException;

	/** The field is introduced here to prevent situation when Client will
     *  be fantastically fast in finding out presence of a newly-created
     *  Universal Servant and will attempt to invoke its operations too
     *  early. In this case Gateway itself will postpone its attempt to
     *  further propagate operation until lock on object is released. */
	public volatile Boolean isInitialLockReleased;

	public DynObject(String[] ids_) {

		super();
		ids = ids_;
        isException = new Boolean(false);
        isInitialLockReleased = new Boolean(false);
	}

    public void invoke(org.omg.CORBA.ServerRequest request) {

        String pcoName = CorbaServer.getCodecObject().
			getCorbaObjectPool().getObject(this).getPcoName();

        if (pcoName == null) pcoName = "$unregistered";

        System.out.println("DynObject::invoke(): " + pcoName +
						   ": received operation call.");

        ClientPool.callOperation(this, request);
    }
}
