Je sais que ca a l'aire compliqué mais avec un ti exemple, vous aller vite comprendre.
J'ai des méthodes qui quand elles sont appeler realise des operations similaires entre elle.
Je voudrais donc ne les ecrirent qu'une fois.
Mon probleme c'est que je ne sais pas les mettre dans une sous methode. en effet,
j'ai besoin du temps d'execution, du nombre d'element present dans une hashmap avant, apres execution.
Exemple :
public Map executeRemoteLoadSpecialists()
{
Map<String, Object> mapResult = new HashMap<String, Object>();
try
{
mapResult.put(METHODE_NAME, "executeRemoteLoadSpecialists" );
long lTimeBefore = System.currentTimeMillis();
executeLoadSpecialists();
long lTimeAfter = System.currentTimeMillis();
mapResult.put(USED_TIME, doFormatUsedTime(lTimeBefore, lTimeAfter));
mapResult.put(STATUS, STATUS_OK);
}
catch(Exception ex)
{
m_logger.error("*** StaticDataService : executeRemoteLoadSpecialists() : Exception", ex);
mapResult.clear();
mapResult.put(STATUS, STATUS_KO);
}
return mapResult;
}
public Map executeRemoteLoadAllIndexes()
{
Map<String, Object> mapResult = new HashMap<String, Object>();
try
{
mapResult.put(METHODE_NAME, "executeRemoteLoadAllIndexes" );
long lTimeBefore = System.currentTimeMillis();
mapResult.put(COUNT_BEFORE, "" + m_mapIDXByIsinData.size());
m_mapIDXByIsinData.clear();
executeLoadAllIndexes();
mapResult.put(COUNT_AFTER, "" + m_mapIDXByIsinData.size());
long lTimeAfter = System.currentTimeMillis();
mapResult.put(USED_TIME, doFormatUsedTime(lTimeBefore, lTimeAfter));
mapResult.put(STATUS, STATUS_OK);
}
catch(Exception ex)
{
m_logger.error("*** StaticDataService : executeRemoteLoadAllIndexes() : Exception", ex);
mapResult.clear();
mapResult.put(STATUS, STATUS_KO);
}
return mapResult;
}
Vous allez me dire que je peut la diviser en 2 sous fonctions (une avant, l'autre apres). Oui, mais d'abord, c'est pas aussi beau, mais en plus, c'est méthodes sont ajouter automatiquement (par introspection) dans mon client.ce préfererais un truc du genre
public Map executeRemoteLoadAllIndexes(String methodeName, Map map, boolean isWidthTime)
{
Map<String, Object> mapResult = new HashMap<String, Object>();
try
{
mapResult.put(METHODE_NAME, methodeName);
long lTimeBefore = System.currentTimeMillis();
(map!=null)mapResult.put(COUNT_BEFORE, "" + m_map.size());
m_map.clear();
executerLaMethode(methodeName);
(map!=null)mapResult.put(COUNT_AFTER, "" + m_map.size());
long lTimeAfter = System.currentTimeMillis();
if(isWidthTime)mapResult.put(USED_TIME, doFormatUsedTime(lTimeBefore, lTimeAfter));
mapResult.put(STATUS, STATUS_OK);
}
catch(Exception ex)
{
m_logger.error("*** StaticDataService : executeRemoteLoadAllIndexes() : Exception", ex);
mapResult.clear();
mapResult.put(STATUS, STATUS_KO);
}
return mapResult;
}
Voila ce que je voudrais faire. Est-ce possible, si oui est ce que vous pouvez me donner qlq pistes. Bien à vous, et merci d'avance.