Si ho scritto
codice:
out.writeObject(new Integer(idUtente));
perchè il prof in ogni esercizio di questo argomento scrive sempre così
Se vedi nel run() cè questo pezzo di codice
codice:
if (op.equals("ric"))
{
int i = ((Integer)in.readObject()).intValue();
try
{
Risorsa r = g.richiedi(i);
out.writeObject(r);
}
....
quando leggo l'oggetto dal socket nel metodo dello stub con readObject
codice:
try
{
tmp = in.readObject();
}
catch (ClassNotFoundException e)
{
throw new IOException();
}
if (tmp instanceof GiaAssegnata)
throw (GiaAssegnata)tmp;
else if (tmp instanceof InterruptedException)
throw (InterruptedException)tmp;
else
return (Risorsa)tmp;
mi ritrovo un altro riferimento ad un oggetto Risorsa. Dico questo perchè nella classe che implementa l'interfaccia ho messo questo campo statico
codice:
public static Risorsa richiesta;
che mi memorizza il riferimento dell'oggetto che restituisce il richiedi di questa classe.
Infatti ci ho messo nel suo codice
codice:
richiesta = memo[i];
Non l'ho riportato prima, ma per verificare che i riferimenti siano uguali ho messo un if-else nel richiedi dello stub. Ecco dove l'ho messo:
codice:
public Risorsa richiedi(int idUtente) throws GiaAssegnata, InterruptedException, IOException
{
Object tmp = null;
out.writeObject("ric");
out.writeObject(new Integer(idUtente));
try
{
tmp = in.readObject();
}
catch (ClassNotFoundException e)
{
throw new IOException();
}
if (tmp instanceof GiaAssegnata)
throw (GiaAssegnata)tmp;
else if (tmp instanceof InterruptedException)
throw (InterruptedException)tmp;
else
{
if ((GestoreRisorseImpl.richiesta) == tmp)
System.out.println("Stesso riferimento");
else
System.out.println("Riferimento diverso");
return (Risorsa)tmp;
}
}