Commit d287c7fa authored by Amadeu Andrade Barbosa Junior's avatar Amadeu Andrade Barbosa Junior
Browse files

[commit para paulorf] Alteração no sdk do java do openbus para incluir suporte...

[commit para paulorf] Alteração no sdk do java do openbus para incluir suporte a instrumentação. Inclui código para cadastrar o interceptador de instrumentação além do interceptador do openbus.

git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/branches/OB_SDK_JAVA_INSTR_v1_05_2010_05_13@121238 ae0415b3-e90b-0410-900d-d0be9363c56b
parent b0d63ca2
Pipeline #484 skipped
......@@ -5,10 +5,10 @@
<groupId>tecgraf.openbus</groupId>
<artifactId>openbus-demo-delegate</artifactId>
<packaging>jar</packaging>
<version>1.5.1</version>
<version>1.5-SNAPSHOT</version>
<name>OpenBus Demo Delegate</name>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/tags/OB_SDK_JAVA_v1_05_01_2011_03_23/demo/delegate</url>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/branches/OB_SDK_JAVA_v1_05_2010_05_13/demo/delegate</url>
<properties>
<java.version>1.5</java.version>
......
......@@ -5,10 +5,10 @@
<groupId>tecgraf.openbus</groupId>
<artifactId>openbus-demo-eventsink</artifactId>
<packaging>jar</packaging>
<version>1.5.1</version>
<version>1.5-SNAPSHOT</version>
<name>OpenBus Demo EventSink</name>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/tags/OB_SDK_JAVA_v1_05_01_2011_03_23/demo/eventsink</url>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/branches/OB_SDK_JAVA_v1_05_2010_05_13/demo/eventsink</url>
<properties>
<java.version>1.5</java.version>
......
ChannelHost = localhost
ChannelPort = 3002
#nsHost = localhost
#nsPort = 3002
ChannelName = MyEventChannel
ChannelID = EventChannel
isExclusive=false
InterceptedMethods = methodA;methodB;methodC;methodD;callA;callB;callC;callD;sayHello;getDataDescription;getDataView;getDataViewSeq;getRoots;getChildren;getParent;createData;copyData;moveData;updateData;deleteData;copyDataFrom;updateDataFrom;getReferences;getProject;startup;shutdown;register;unregister;getComponent;renewLease;loginByPassword;loginByCertificate;getChallenge;credentialWasDeleted;logout;isValid;areValid;getEntryCredential;getAllEntryCredential;addObserver;removeObserver;addCredentialToObserver;removeCredentialFromObserver;addSystem;removeSystem;setSystemDescription;getSystems;getSystem;addSystemDeployment;removeSystemDeployment;setSystemDeploymentDescription;getSystemDeploymentCertificate;setSystemDeploymentCertificate;getSystemDeployments;getSystemDeployment;getSystemDeploymentsBySystemId;addUser;removeUser;setUserName;getUser;getUsers;getIdentifier;addMember;removeMember;getMembers;createSession;getSession
Metrics = CPUUsageCollector;AvgCPUUsageCollector;CPUTimeCollector;ElapsedTimeCollector;IOReadTimeCollector
......@@ -5,10 +5,10 @@
<groupId>tecgraf.openbus</groupId>
<artifactId>openbus-demo-hello</artifactId>
<packaging>jar</packaging>
<version>1.5.1</version>
<version>1.5-SNAPSHOT</version>
<name>OpenBus Demo Hello</name>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/tags/OB_SDK_JAVA_v1_05_01_2011_03_23/demo/hello</url>
<url>https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/java/branches/OB_SDK_JAVA_v1_05_2010_05_13/demo/hello</url>
<properties>
<java.version>1.5</java.version>
......
......@@ -3,5 +3,5 @@ password = tester
host.name = localhost
host.port = 2089
entity.name = HelloService
private.key = demo/hello/resources/HelloService.key
acs.certificate = demo/hello/resources/AccessControlService.crt
private.key = resources/HelloService.key
acs.certificate = resources/AccessControlService.crt
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDIBg9a2kSIrU4NpKtyXyEHgSCr
LMkaOrSt4aS6jES/GDWJwvFqSipzQBClUFatlzVYWURs6auEI8EHn4sC6VBnYcFvGtsL9Axyf8k9
DxZK9G+o5K0GA9UuNb68zSEWXrevkwur3O4BcFWHj4Iv5ZJnjtp9YTc8ieLLNY6jDmGmkI76xbPU
LEVVIA/BicWUP+7XtEYQ9oY7B2NnVGjOQczgVAL/F3o5T7s+MX0a5oSy+Cq0dXdVn7AyyrXuRTLM
irxKZgx6yzB6bzrTDmeCMh/K2UBstZZoh4OVtFPLHfTDv1LqqtVmBJREucF4nlJ4KsWmpEva1U2G
Tev/4mg4O1jJAgMBAAECggEAIEUCAylFdztmZUMUuc3pGTnW2GbQRuADuC24ErSAfsfcE06U/g3b
DV7fkJwGb9j+LTOxm1STbC0MfjtaBO05IISf3VnazvHfdDVzdNtTQGJxBTFnTJofsWXQUMtTNDWx
sqypbF+nMio6UjVvzmReG0DrtOCTNbwVD62jRmESlflhYjCtKK+VSgz/7RXNRKywhxl8/ExVe2Ln
GuT5GTd8cyW+qGO4zaLI3IFEMc8er2qWC/qOc8LASFgYxdy7T4dQcQR+3R6Et7oCb5LAfyU/veyt
GCTmwxBscn44lBn6/80sZqJ+Cpr/w1bg3CsPOG4e8raAM3iYiV4IzdGc6TRYtQKBgQDlh6xtd7Gh
B4J1JUnnIb5mjrshNIVlRvelFl9jM3o39PHxiUHfd/RbzpfuvtvNKfaUU2f5a/KFTd3O90GhzS5K
6mHKoie7oF5fMJoBzWilfduRRd1CIK/t2P5yTzfoxUXmiahjUhoZLorU3BJdx2IrroLP/5tvIe1e
XR4x0O9+MwKBgQDfF0h08ANGMpZdbEp3Kz/Qff+bUHw5MmyDp2shlv0AuRCGWwWW2TEusF2QgzwG
rFmc/+vZn1ztB1i32R+TgmJ4+ERgBkUgx5kllwvF22NaBWiItNolvqxUK+Dt2Uwf81UTR/nuPNvG
WwEVv2P+30mrdG1w3VAxTAeXitWUWlYZEwKBgCTXNPbRCmK1SNwyov0FLoFZkXGP84VA8ci+oYrT
nV9T4m2JQVhz8XW24C4C1lbE0H4YMQ0YpXF+AQcSKqekvjRqEE4s3sG/yMXwkBeP96bwX4ietRfD
FVnQxW5lhqzG1SRenfdrGyNFlCT8ObpxoTEvrnFiLnmU8Xt+6LTIO1h/AoGBAMAPRmTOALOdd5Ak
W5Num3i+EKFA0EFZpMxPBM8dMuE9cfmJQS2V/F6KnXJ9WN8R3/Bm70Aij5jMO1fDyAhxNp+YdR0K
KNdInxMaj5sd/dGRWGZg9HGMTsYEJJf//CaBkZuQ2p18rWR+ElgLtmXFC6JdEJ8bGR/nqZ2Qe8FF
aFwbAoGAGyUL4zaALWgAyBc387VXiu4nyBzn6rk3XIAHObRduRnJODRbyUeWs7zBT8datLYyFvS0
yl3ifq3apth+218LTdYsWLCPdjIBjuWg0nuD/1aHrY7xSuNzWu9J0kle4FQve5pTkJ2Bqv4dIf+N
LWcjr9JqtxFa4NiiIh8vkmaADrE=
-----END PRIVATE KEY-----
package tecgraf.openbus.demo.hello;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
......@@ -10,6 +13,7 @@ import org.omg.CORBA.UserException;
import scs.core.IComponent;
import tecgraf.openbus.Openbus;
import tecgraf.openbus.core.v1_05.registry_service.IRegistryService;
import tecgraf.openbus.core.v1_05.registry_service.Property;
import tecgraf.openbus.core.v1_05.registry_service.ServiceOffer;
import tecgraf.openbus.exception.OpenBusException;
import tecgraf.openbus.exception.RSUnavailableException;
......@@ -20,6 +24,13 @@ import demoidl.hello.IHelloHelper;
public class HelloClient {
public static void main(String[] args) throws OpenBusException,
UserException, IOException {
boolean instrumentationActive = true;
//Arguments checking
for (String arg:args) {
if (arg.equalsIgnoreCase("-di")) instrumentationActive = false;
}
Properties props = new Properties();
InputStream in = HelloClient.class.getResourceAsStream("/Hello.properties");
try {
......@@ -49,16 +60,55 @@ public class HelloClient {
throw new RSUnavailableException();
}
IComponent component=null;
ServiceOffer[] servicesOffers =
registryService.find(new String[] { "IHello" });
ServiceOffer serviceOffer = servicesOffers[0];
IComponent component = serviceOffer.member;
if (servicesOffers.length == 0) {
System.out.println("No service offer found for interface IHello.");
System.exit(1);
}
for (ServiceOffer offer:servicesOffers) {
for (Property prop:offer.properties) {
System.out.println(prop.name);
if (prop.name.equalsIgnoreCase("instrumentation")) {
if (instrumentationActive) {
if (prop.value[0].equalsIgnoreCase("active")) {
System.out.println("Using IHello: Instrumentation ACTIVE.");
component = offer.member;
break;
}
}
}
else {
if (!instrumentationActive) {
component = offer.member;
break;
}
}
if (component != null) break;
}
}
if (component == null) {
System.out.println("Probably no service found with instrumentation active.");
System.exit(1);
}
org.omg.CORBA.Object helloObject = component.getFacetByName("IHello");
IHello hello = IHelloHelper.narrow(helloObject);
hello.sayHello();
FileWriter w=new FileWriter(new File("times-no-instrumentation.txt"));
ArrayList<Long> times = new ArrayList<Long>();
for (int i=0; i<20;i++){
long initialTime = System.nanoTime();
hello.sayHello();
long finalTime = System.nanoTime() - initialTime;
System.out.printf("Registered time: %d",finalTime);
w.write(String.format("%d \n",finalTime));
times.add(new Long(finalTime));
}
bus.disconnect();
w.close();
System.out.println("FIM");
for (Long l:times) System.out.printf("%d \n",l.longValue());
}
}
......@@ -87,7 +87,7 @@ public class HelloFTServer {
.getCanonicalName());
ComponentContext context =
builder.newComponent(descriptions, new ComponentId("Hello", (byte) 1,
(byte) 0, (byte) 0, "Java"));
(byte) 0, (byte) 0/*, "Java"*/));
IRegistryService registryService =
bus.connect(entityName, privateKey, acsCertificate);
......
......@@ -10,6 +10,7 @@ public final class HelloImpl extends IHelloPOA {
this.context = context;
}
@Override
public void sayHello() {
System.out.println("Hello !!!");
}
......
......@@ -18,6 +18,7 @@ import scs.core.IComponentHelper;
import scs.core.servant.ComponentBuilder;
import scs.core.servant.ComponentContext;
import scs.core.servant.ExtendedFacetDescription;
import scs.instrumentation.interceptor.StatsServiceInterceptor;
import tecgraf.openbus.Openbus;
import tecgraf.openbus.core.v1_05.registry_service.IRegistryService;
import tecgraf.openbus.core.v1_05.registry_service.Property;
......@@ -40,6 +41,14 @@ public class HelloServer {
GeneralSecurityException, SecurityException, InstantiationException,
IllegalAccessException, ClassNotFoundException, InvocationTargetException,
NoSuchMethodException, OpenBusException {
boolean instrumentationActive = true;
//Arguments checking
for (String arg:args) {
System.out.println(arg);
if (arg.equalsIgnoreCase("-di")) instrumentationActive = false;
}
System.out.printf("WORKING DIR: %s \n",System.getProperty("user.dir"));
Properties props = new Properties();
InputStream in = HelloClient.class.getResourceAsStream("/Hello.properties");
if (in != null) {
......@@ -66,9 +75,16 @@ public class HelloServer {
orbProps.setProperty("org.omg.CORBA.ORBSingletonClass",
"org.jacorb.orb.ORBSingleton");
Openbus bus = Openbus.getInstance();
bus.initWithFaultTolerance(args, orbProps, host, port);
if (instrumentationActive) {
orbProps.put("instrumentation", true);
orbProps.put("serviceName", "HelloService");
orbProps.put("componentName", "HelloServer");
}
//bus.initWithFaultTolerance(args, orbProps, host, port);
System.out.println("instr ="+instrumentationActive);
bus.init(args, orbProps, host, port);
System.out.println("Saiu do init");
String entityName = props.getProperty("entity.name");
String privateKeyFile = props.getProperty("private.key");
String acsCertificateFile = props.getProperty("acs.certificate");
......@@ -87,7 +103,7 @@ public class HelloServer {
.getCanonicalName());
ComponentContext context =
builder.newComponent(descriptions, new ComponentId("Hello", (byte) 1,
(byte) 0, (byte) 0, "Java"));
(byte) 0, (byte) 0/*, "Java"*/));
IRegistryService registryService =
bus.connect(entityName, privateKey, acsCertificate);
......@@ -99,15 +115,23 @@ public class HelloServer {
org.omg.CORBA.Object obj = context.getIComponent();
IComponent component = IComponentHelper.narrow(obj);
Property registrationProps[] = new Property[1];
int propsLen = instrumentationActive?2:1;
Property registrationProps[] = new Property[propsLen];
registrationProps[0] = new Property();
registrationProps[0].name = "facets";
registrationProps[0].value = new String[1];
registrationProps[0].value[0] = "IDL:demoidl/hello/IHello:1.0";
if (instrumentationActive) {
registrationProps[1] = new Property();
registrationProps[1].name = "instrumentation";
registrationProps[1].value = new String[]{"active"};
}
ServiceOffer serviceOffer = new ServiceOffer(registrationProps, component);
try {
registrationId = registryService.register(serviceOffer);
System.out.println("Hello Server registrado.");
System.out.printf("Hello Server registrado. id = %s \n",registrationId);
}
catch (UnathorizedFacets uf) {
System.out.println("No foi possvel registrar Hello Server.");
......
......@@ -168,7 +168,7 @@ Os outros m
Os outros métodos do \emph{stub} do Serviço de Registro serão explicados em mais detalhes a seguir:
\begin{itemize}
\item \code{RegistryIdentifier register(in ServiceOffer aServiceOffer)}: Registra um serviço no barramento. O serviço é descrito através de uma oferta de serviço. Caso o serviço seja registrado com sucesso, a identificação do mesmo é retornada. O identificador é importante para desregistrar a oferta.
\item \code{void register(ServiceOffer serviceOffer, String registryId)}: Registra um serviço no barramento. O serviço é descrito através de uma oferta de serviço. Caso o serviço seja registrado com sucesso, a identificação do mesmo é armazenada no parâmetro de saída registryId.
\item \code{void unregister(String registryId)}: Remove uma oferta de serviço do barramento.
\item \code{ServiceOfferList find(FacetList facets)}: Busca uma ou mais ofertas de serviço no barramento que implementem todas as facetas discriminadas em \emph{facets}.
\item \code{ServiceOfferList findByCriteria(FacetList facets, PropertyList properties)}: Busca uma ou mais ofertas de serviço no barramento que implementem todas as facetas discriminadas em \emph{facets} e que atendam aos critérios descritos no parâmetro \emph{criteria}, que é uma lista de propriedades descrita através de strings no formato chave = {valor1, valor2, ..., valorN}.
......
......@@ -5,7 +5,7 @@
<groupId>tecgraf.openbus</groupId>
<artifactId>openbus-api</artifactId>
<packaging>jar</packaging>
<version>1.5.1</version>
<version>1.5-INSTR08</version>
<name>OpenBus API</name>
......@@ -13,7 +13,10 @@
<java.version>1.5</java.version>
<junit.version>4.6</junit.version>
<scs.version>1.2.0</scs.version>
<scsinstr.version>0.8.0</scsinstr.version>
<scsidl.version>0.8-INSTR</scsidl.version>
<jacorb.version>2.3.0</jacorb.version>
<openbusidl.version>1.5-INSTR08</openbusidl.version>
<source.encoding>ISO-8859-1</source.encoding>
</properties>
......@@ -33,28 +36,6 @@
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.5,1.6)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
......@@ -85,7 +66,7 @@
<version>${jacorb.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-sources</phase>
......@@ -117,20 +98,26 @@
<dependency>
<groupId>tecgraf.openbus</groupId>
<artifactId>openbus-idl-jacorb</artifactId>
<version>${project.version}</version>
<version>${openbusidl.version}</version>
</dependency>
<dependency>
<groupId>tecgraf.scs</groupId>
<artifactId>scs-idl-jacorb</artifactId>
<version>${scs.version}</version>
<groupId>tecgraf.scs.instrumentation</groupId>
<artifactId>scs-instr-idl-jacorb</artifactId>
<version>${scsidl.version}</version>
</dependency>
<dependency>
<groupId>tecgraf.scs</groupId>
<artifactId>scs-core</artifactId>
<version>${scs.version}</version>
</dependency>
<dependency>
<groupId>tecgraf.scs.instrumentation</groupId>
<artifactId>scs-instrumentation</artifactId>
<version>${scsinstr.version}</version>
</dependency>
<dependency>
<groupId>org.jacorb</groupId>
......
......@@ -34,6 +34,8 @@ import scs.core.IComponentHelper;
import scs.core.IReceptacles;
import scs.core.IReceptaclesHelper;
import scs.core.InvalidName;
import scs.instrumentation.interceptor.StatsServiceInterceptor;
import scs.instrumentation.interceptor.InstrLogger;
import tecgraf.openbus.authenticators.Authenticator;
import tecgraf.openbus.authenticators.CertificateAuthenticator;
import tecgraf.openbus.authenticators.LoginPasswordAuthenticator;
......@@ -65,6 +67,7 @@ import tecgraf.openbus.lease.LeaseRenewer;
import tecgraf.openbus.session_service.v1_05.ISessionService;
import tecgraf.openbus.session_service.v1_05.ISessionServiceHelper;
import tecgraf.openbus.util.Log;
import tecgraf.openbus.util.TestLogger;
import tecgraf.openbus.util.Utils;
/**
......@@ -132,6 +135,10 @@ public final class Openbus {
* <i>Callback</i> para a notificao de que um <i>lease</i> expirou.
*/
private LeaseExpiredCallback leaseExpiredCallback;
/**
* Servio de registro.
*/
private IRegistryService rgs;
/**
* Servio de sesso.
*/
......@@ -259,6 +266,7 @@ public final class Openbus {
public void init(String[] args, Properties props, String host, int port,
CredentialValidationPolicy policy) throws UserException,
OpenbusAlreadyInitializedException {
System.out.println("*-----------------------------------------------------------------");
if (orb != null) {
throw new OpenbusAlreadyInitializedException();
}
......@@ -270,7 +278,6 @@ public final class Openbus {
"O campo 'port' no pode ser negativo.");
this.host = host;
this.port = port;
if (props == null)
throw new IllegalArgumentException("O campo 'props' no pode ser null");
String clientInitializerClassName = ClientInitializer.class.getName();
......@@ -281,19 +288,46 @@ public final class Openbus {
props.put(
ORB_INITIALIZER_PROPERTY_NAME_PREFIX + serverInitializerClassName,
serverInitializerClassName);
if (Boolean.parseBoolean(props.getProperty("instrumentation"))) {
String statsServiceORBInitializerClass =
"scs.instrumentation.interceptor.StatsServiceORBInitializer";
props.setProperty(ORB_INITIALIZER_PROPERTY_NAME_PREFIX +
statsServiceORBInitializerClass, statsServiceORBInitializerClass);
//props.remove("instrumentation");
}
String serviceName = null;
String componentName = null;
if (props.containsKey("serviceName")) {
serviceName = props.getProperty("serviceName");
componentName = props.getProperty("componentname",serviceName);
}
new TestLogger(this.getClass().getSimpleName()+(serviceName!=null?serviceName:"") + Thread.currentThread().getId());
// A poltica deve ser definida antes do ORB.init pois o
// ServerInitializer
// utiliza esta propriedade.
this.credentialValidationPolicy = policy;
addInterceptedMethods();
for(String str:args) System.out.println(str);
for(String str:props.stringPropertyNames()) System.out.println(str + " "+props.getProperty(str));
this.orb = org.omg.CORBA.ORB.init(args, props);
if (StatsServiceInterceptor.isInstanced()){
System.out.printf("Setando o nome do servio: %s", serviceName);
StatsServiceInterceptor.getInstance(null,0,null,null).
setServiceInfo(serviceName, componentName);
}
System.out.println("obtendo referencia do ROOTPOA");
org.omg.CORBA.Object obj = this.orb.resolve_initial_references("RootPOA");
System.out.println("narrow");
this.rootPOA = POAHelper.narrow(obj);
System.out.println("get manager");
POAManager manager = this.rootPOA.the_POAManager();
System.out.println("manager.activate");
manager.activate();
System.out.println("saindo init");
}
/**
......@@ -439,13 +473,14 @@ public final class Openbus {
* @return O Servio de Registro.
*/
public IRegistryService getRegistryService() {
if (this.rgs != null)
return this.rgs;
if (this.ic == null)
return null;
Object objRecep = this.ic.getFacetByName(Utils.RECEPTACLES_NAME);
IReceptacles ireceptacle = IReceptaclesHelper.narrow(objRecep);
IRegistryService registryService = null;
try {
ConnectionDescription[] connections =
ireceptacle.getConnections(Utils.REGISTRY_SERVICE_RECEPTACLE_NAME);
......@@ -454,11 +489,11 @@ public final class Openbus {
IComponent registryComponent = IComponentHelper.narrow(objRef);
Object objReg =
registryComponent.getFacetByName(Utils.REGISTRY_SERVICE_FACET_NAME);
registryService = IRegistryServiceHelper.narrow(objReg);
this.rgs = IRegistryServiceHelper.narrow(objReg);
if (this.isFaultToleranceEnable) {
registryService._set_policy_override(
new Policy[] { this.timeOutPolicy }, SetOverrideType.ADD_OVERRIDE);
this.rgs._set_policy_override(new Policy[] { this.timeOutPolicy },
SetOverrideType.ADD_OVERRIDE);
}
}
}
......@@ -466,7 +501,7 @@ public final class Openbus {
Log.COMMON.severe("No foi possvel obter o servio de registro.", e);
}
return registryService;
return this.rgs;
}
/**
......@@ -706,6 +741,11 @@ public final class Openbus {
* nenhuma conexo estiver ativa.
*/
public synchronized boolean disconnect() {
TestLogger.getInstance().close();
if (StatsServiceInterceptor.isInstanced()) {
InstrLogger log = InstrLogger.getInstance("");
log.close();
}
if (this.credential == null)
return false;
......@@ -743,6 +783,7 @@ public final class Openbus {
*/
private void reset() {
this.acs = null;
this.rgs = null;
this.lp = null;
this.ft = null;
this.ic = null;
......
......@@ -3,8 +3,6 @@
*/
package tecgraf.openbus.interceptors;
import java.lang.reflect.Method;
import org.omg.CORBA.Any;
import org.omg.CORBA.ORB;
import org.omg.IOP.Codec;
......@@ -18,6 +16,7 @@ import tecgraf.openbus.access_control_service.CredentialWrapper;
import tecgraf.openbus.core.v1_05.access_control_service.Credential;
import tecgraf.openbus.core.v1_05.access_control_service.CredentialHelper;
import tecgraf.openbus.util.Log;
import tecgraf.openbus.util.TestLogger;
/**
* Implementa um interceptador "cliente", para insero de informaes no
......@@ -27,7 +26,12 @@ import tecgraf.openbus.util.Log;
*/
class ClientInterceptor extends InterceptorImpl implements
ClientRequestInterceptor {
TestLogger log = TestLogger.getInstance();
ThreadLocal<Long> requestStart = new ThreadLocal<Long>();
ThreadLocal<String> requestid = new ThreadLocal<String>();
/**
* Constri o interceptador.
*
......@@ -44,29 +48,27 @@ class ClientInterceptor extends InterceptorImpl implements
public void send_request(ClientRequestInfo ri) {
Log.INTERCEPTORS.info("Operao {" + ri.operation()
+ "} interceptada no cliente.");
for (Method op : org.omg.CORBA.Object.class.getMethods()) {
if (ri.operation().equals(op.getName())) {
Log.INTERCEPTORS.fine(String.format(
"O mtodo {} pertence a interface {} e no ser interceptado", op
.getName(), org.omg.CORBA.Object.class.getCanonicalName()));
return;
}
}
long sReqInit = System.nanoTime();
requestStart.set(sReqInit);
requestid.set(String.format("%s-%f", ri.operation(),new Double(System.nanoTime())/10000));
//operacoes do ORB nao precisam de credencial
for (java.lang.reflect.Method op : ClientInterceptor.class.getMethods()) {
if (ri.operation().equals(op.getName()) ) return;
}
Openbus bus = Openbus.getInstance();
/* Verifica se existe uma credencial para envio */
Credential credential = bus.getCredential();
if ((credential == null) || (credential.identifier.equals(""))) {
Log.INTERCEPTORS
.info("Operao {" + ri.operation() + "} SEM CREDENCIAL!");
Log.INTERCEPTORS.info("Operao {" + ri.operation()
+ "} SEM CREDENCIAL!");
return;
}
CredentialWrapper wrapper = new CredentialWrapper(credential);
Log.INTERCEPTORS.info("Operao {" + ri.operation() + "} Credencial: "
+ wrapper);
Log.INTERCEPTORS.info("Operao {" + ri.operation()
+ "} Credencial: " + wrapper);
/* Insere a credencial no contexto do servio */
byte[] value = null;
......@@ -78,11 +80,13 @@ class ClientInterceptor extends InterceptorImpl implements
}
catch (Exception e) {
Log.INTERCEPTORS.severe("Operao {" + ri.operation()
+ "} ERRO NA CODIFICAO DA CREDENCIAL!", e);
+ "} ERRO NA CODIFICAO DA CREDENCIAL!", e);
return;
}
ri
.add_request_service_context(new ServiceContext(CONTEXT_ID, value), false);