• Keine Ergebnisse gefunden

Excercise Sheet 4 Solution

N/A
N/A
Protected

Academic year: 2022

Aktie "Excercise Sheet 4 Solution"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Prof. Dr. rer. nat. Roland Wism ¨uller

Excercise Sheet 4 Solution

Lecture Distributed Systems Summer Term 2021

Exercise 1: Programming: Java-RMI - Follow-up example

You will find the solution to this problem in in the archivel04eFiles.zip1on the lecture’s web page.

Exercise 2: Programming: Generic proxy objects

You will find the solution to this problem in in the archivel04eFiles.zip2on the lecture’s web page.

Exercise 3: Generic dispatcher with Java Reflection

a) The request message must in any case contain the following information:

(i) an identifier for the object on which the method is to be called, (ii) a specification of the method to be called,

(iii) the arguments for the method call.

In the simplest case, the object ID can be a sequence number. The server skeleton must then, for example, maintain an array that contains references to all remote objects of the server.

The method to be called could be specified by its name. Due to the possibility of overloading, however, this may not be sufficient, but the parameter types must also be specified. The Java class Classcontains a method getMethod(), which is used to find the correspondingMethod object for a given name and the parameter types.3SinceMethoditself cannot be serialized, the message cannot directly contain theMethodobject.

The arguments for the method call are most easily transferred in Java as serialized objects. The arguments for RMI must always be either serializable or remote objects. In the latter case, the associated stub object is serialized during the call.

The Java data type for a query message could therefore look as follows:

public class RequestMessage implements Serializable {

int objectID;

String methodName;

Class<?>[] argumentTypes;

Object[] arguments;

...

}

b) With the above query message type, the code for a generic dispatcher might look something like this:

1http://www.bs.informatik.uni-siegen.de/web/wismueller/vl/vs/l04eFiles.zip

2http://www.bs.informatik.uni-siegen.de/web/wismueller/vl/vs/l04eFiles.zip

3However, the parameter types must match the specified types exactly. In principle, the method could also be determined automatically from the types of the passed arguments. However, these can be subclasses of the parameter types, so that the search for the suitable method is not trivial. The Java classClassdoes not offer a method for this either.

1

(2)

public void dispatch(RequestMessage request) {

try {

// Determine reference to target object from objectID Object target = objectTable[request.objectID];

// Determine the appropriate Method object via the Class object Method method = target.getClass().getMethod(request.methodName,

request.argumentTypes);

// Call method

Object result = method.invoke(target, request.arguments);

... pack result into reply message package and send back }

catch (InvocationTargetException e) { // Called method threw an exception

... pack e.getCause() into reply message package and send back }

catch (Exception e) {

// Exception when calling the method (e.g. IllegalArgumentException) ... pack e into reply message package and send back

} }

Exercise 4: Parameter passing

Ifcall-by-referenceis used, a pointer toiis passed toincr. This will incrementitwice, so the end result in this case is 2.

Withcall-by-valuethe value is passed directly and no reference toi. Thereforeiremains unchanged for the caller, i.e. 0.

Call-by-copy/resultmeans: Copying the parameter values when calling the procedure, copying back and overwriting the call parameters when the procedure is finished. In this case,iis passed as a value twice (i.e. 0 each) and incremented so that both values are now 1. If they are copied back, the second copy overwrites the first and the final value is now also 1.

Exercise 5: Transparency of Java RMI

The solutions of the programming task can be found in the archivel04eFiles.zip4on the lecture’s web page. The pro- blem is the parameter passing in Java RMI, which has acall by valuesemantics for serializable objects (andArrayList is serializable). I.e., the server sorts the list correctly, but the result has no influence on the client.

To fix the problem, you might get the idea to make the list a remote object located at the client, so that the server can modify it via RMI. However, since sorting anArrayListresults in an extremely large number of accesses, this procedure would be extremely inefficient. It is therefore more efficient to realize a parameter passing withcall by value and result semantics by having thesort()method of the remote interfaceSortServerreturn the sorted list as the return value andsort()method of the wrapper class copy this return value back to the original list.

4http://www.bs.informatik.uni-siegen.de/web/wismueller/vl/vs/l04eFiles.zip

2

Referenzen

ÄHNLICHE DOKUMENTE

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method

Advanced Aspects of Object-Oriented Programming (SS 2011) Practice Sheet 1 Date of Issue: 19.04.11. Deadline: - (until 10 a.m. Note: Have a look at the Java API documentation of

In general, the presence of a distributed parameter function can be successfully treated in the RB context with an optimization greedy even if it is not affine, since with this

Summary: The present study shows an increased urinary cyclic guanosine S'.S'-monophosphate (cyclic GMP) excre- tion rate in children of all age groups bearing malignant tumours

In a recent paper V.P.Demyanov, S.Gamidov and T.J.Sivelina pre- sented an algorithm for solving a certain type of quasidiffer- entiable optimization problems [3].. In this PaFer

If we compare this procedure to the estimators based on the conventional propensity score, conven- tional propensity score combined with trimming rule 1 as well as the

In recent years, methods for DLP have been developed which make-it possible to take into account the specific features of dynamic problems [7,9].* But extension of the

0.3 M HCl by diluting concentrated HCl (Merck supra pure) 0.8 M ammonia by diluting 25% NH4OH (Fluka supra pure) 0.1M H2O2 by diluting 30% H2O2 (Merck supra pure)..