Here is a small example of using dynamic proxies in Java. A proxy wraps any object implementing any interface and takes control of method invocation on this object. This code sample shows how one can wrap a remote RMI object with a proxy that will retry multiple times any method call on this object in case of network error.
JAVA:
-
import java.lang.reflect.* ;
-
import java.rmi.Remote ;
-
-
-
{
-
private final static int MAX_TRY = 3 ;
-
-
-
-
private RetryProxy
(Object anObject
)
-
{
-
object = anObject ;
-
}
-
-
public static Object newInstance
(Object obj,
Class anInterface
)
-
{
-
if ((null == obj) || (null == anInterface))
-
{
-
-
}
-
-
Class[] interfaces = {anInterface} ;
-
-
return Proxy.
newProxyInstance ( obj.
getClass().
getClassLoader(),
-
interfaces,
-
new RetryProxy (obj)) ;
-
}
-
-
-
{
-
for (int i = 0; i <(MAX_TRY - 1); i++)
-
{
-
try
-
{
-
return m.invoke (object, args) ;
-
}
-
-
{
-
}
-
}
-
-
try
-
{
-
return m.invoke (object, args) ;
-
}
-
-
{
-
throw ex.getTargetException() ;
-
}
-
}
-
-
public static void main
(String[] args
)
-
{
-
// Get the reference to a remote object
-
//
-
Pingable remoteClient = ... ;
-
-
// Wrap this RMI object into with RetryProxy
-
//
-
remoteClient = (Pingable) RetryProxy.newInstance (test, Pingable.class) ;
-
-
// Try to ping the remote.
-
//
-
System.
out.
println (remoteClient.
ping()) ;
// RMI Call
-
}
-
}
Blog
Java
Dans le cadre du développement du logiciel ADE, chez ADESOFTware, j'ai pu mettre en place une base de données relationnelle HSQLDB. Ce système remplace avantageusement MSAccess pour une installation de test ou un maquettage. Tout comme Access, aucune installation n'est nécessaire, seul un fichier contenant le script de création des tables est requis. Contrairement à Access, les performances sont étonnantes pour des bases de taille raisonnable. Read more...
Blog
Database, Java, Testing
jTDS est un excellent driver JDBC pour SQL Server. Il s'agit d'un driver 100% Java (donc de type 4) compatible avec JDBC 3.0. Ce qui est particulièrement remarquable, c'est le gain de vitesse visible que l'on obtient par rapport au driver ODBC par défaut. Ce gain est d'autant plus visible que l'on utilise la version 2000 de SQL server car la dernière version de jTDS apporte le support du protocole de communication TDS en version 8.0.
Couplé à MSDE, on obtient un ensemble homogène et gratuit aux performances excellentes pour des applications professionnelles. Je préfère d'ailleurs cette solution à un MySql. L'outil graphique de gestion de la base qui accompagnera SQL Server 2005 Express sera sans aucun doute un atout supplémentaire.
Blog
Database, Java