Commit 6fe7a718 authored by Rodrigo Carneiro Henrique's avatar Rodrigo Carneiro Henrique
Browse files

[SCS-249]: Alterar o método removeConnection de scs.core.Receptacle para...

[SCS-249]: Alterar o método removeConnection de scs.core.Receptacle para receber o identificador de uma conexão e não o description


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/scs/core/java/trunk@114864 ae0415b3-e90b-0410-900d-d0be9363c56b
parent 92150b8b
......@@ -10,7 +10,7 @@ public class IReceptaclesServant extends IReceptaclesPOA {
* Referência para o contexto do componente. O contexto provém facilidades
* para acesso a dados compartilhados entre as diversas facetas
*/
protected ComponentContext myComponent;
private ComponentContext myComponent;
/**
* Construtor padrão que recebe o contexto do componente.
......@@ -49,24 +49,20 @@ public class IReceptaclesServant extends IReceptaclesPOA {
*/
public synchronized void disconnect(int id) throws InvalidConnection,
NoConnection {
if (id < 0) {
if (id <= 0) {
throw new InvalidConnection();
}
ConnectionDescription connDesc = null;
boolean disconnected = false;
for (Receptacle receptacle : myComponent.getReceptacles()) {
for (ConnectionDescription desc : receptacle.getConnections()) {
if (desc.id == id) {
connDesc = desc;
break;
}
}
if (connDesc != null) {
receptacle.removeConnection(connDesc);
return;
if (receptacle.removeConnection(id)) {
disconnected = true;
break;
}
}
throw new NoConnection();
if (!disconnected) {
throw new NoConnection();
}
}
/**
......
......@@ -124,13 +124,24 @@ public class Receptacle {
* Remove uma conexo pelo seu identificador
*
* @param id Identificador da conexo
* @throws InvalidConnection
* @throws NoConnection
*/
public synchronized void removeConnection(ConnectionDescription desc)
throws NoConnection {
if (!connections.remove(desc)) {
throw new NoConnection();
public synchronized boolean removeConnection(int id) {
if (id <= 0) {
throw new IllegalArgumentException(
"The connection's id can't be less than zero");
}
int connectionIndex = -1;
for (int i = 0; i < this.connections.size(); i++) {
ConnectionDescription connection = this.connections.get(i);
if (connection.id == id) {
connectionIndex = i;
break;
}
}
if (connectionIndex == -1) {
return false;
}
this.connections.remove(connectionIndex);
return true;
}
}
......@@ -14,7 +14,7 @@ import org.omg.PortableServer.POAHelper;
import scs.core.exception.SCSException;
public final class IReceptacleTest {
public final class ReceptacleTest {
private static ComponentContext context;
private static String name;
private static String interfaceName;
......@@ -124,11 +124,24 @@ public final class IReceptacleTest {
Receptacle receptacle =
new Receptacle(context, name, interfaceName, multiplex);
POA poa = context.getPOA();
byte[] id =
poa.servant_to_id(new IReceptaclesServant(context));
byte[] id = poa.servant_to_id(new IReceptaclesServant(context));
org.omg.CORBA.Object obj = poa.id_to_reference(id);
receptacle.addConnection(obj);
Assert.assertEquals(1, receptacle.getConnectionsSize());
poa.deactivate_object(id);
}
@Test(expected = IllegalArgumentException.class)
public void removeConnection() throws UserException {
Receptacle receptacle =
new Receptacle(context, name, interfaceName, multiplex);
receptacle.removeConnection(0);
}
@Test
public void removeConnection2() throws UserException {
Receptacle receptacle =
new Receptacle(context, name, interfaceName, multiplex);
Assert.assertFalse(receptacle.removeConnection(1));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment