Beispiel #1
0
        public void GetConnectionsSizeTest()
        {
            Receptacle target = new Receptacle(name, interfaceName, isMultiple);
            int        actual;
            int        expected;

            for (int i = 0; i < connections.Count; i++)
            {
                target.AddConnections(connections[i]);
                actual   = target.GetConnectionsSize();
                expected = i + 1;
                Assert.AreEqual(expected, actual);
            }

            int id = target.AddConnections(connections[0]);

            expected = connections.Count + 1;
            actual   = target.GetConnectionsSize();
            Assert.AreEqual(expected, actual);

            target.RemoveConnetions(id);
            expected = connections.Count;
            actual   = target.GetConnectionsSize();
            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        /// <summary>
        /// Conecta uma faceta a um receptáculo.
        /// </summary>
        /// <param name="receptacle">
        /// O nome do receptáculo que se deseja conectar.
        /// </param>
        /// <param name="obj">
        /// A referência para a faceta que se deseja conectar.
        /// </param>
        /// <exception cref="InvalidName">
        /// Caso o nome do receptáculo seja inválido.
        /// </exception>
        /// <exception cref="InvalidConnection">
        /// Caso a conexão não possa ser estabelecida, este erro pode acontecer
        /// caso o <c>obj</c> não implemente a interface do receptáculo.
        /// </exception>
        /// <exception cref="AlreadyConnected">
        /// Caso a faceta já esteja conectada.
        /// </exception>
        /// <exception cref="ExceededConnectionLimit">
        /// Caso o número de conexões tenha excedido o limite configurado.
        /// </exception>
        public int connect(string receptacle, MarshalByRefObject obj)
        {
            IDictionary <string, Receptacle> receptacles =
                context.GetReceptacles();

            if (!receptacles.ContainsKey(receptacle))
            {
                throw new InvalidName {
                          name = receptacle
                }
            }
            ;

            Receptacle rec = receptacles[receptacle];

            if ((!rec.IsMultiple) &&
                (rec.GetConnectionsSize() > 0))
            {
                throw new AlreadyConnected();
            }

            if (!IiopNetUtil.CheckInterface(obj, rec.InterfaceName))
            {
                throw new InvalidConnection();
            }

            int id = rec.AddConnections(obj);

            logger.InfoFormat("Conexão {0} adicionada ao receptáculo '{1}'", id,
                              receptacle);
            return(id);
        }