- private static void sendNextObject(Object clientOrServer, Object obj)
- throws NoSuchFieldException, NoSuchMethodException,
- ClassNotFoundException, IOException {
- if (clientOrServer instanceof ConnectActionClientObject) {
- ConnectActionClientObject client = (ConnectActionClientObject) clientOrServer;
- client.send(obj);
- } else if (clientOrServer instanceof ConnectActionServerObject) {
- ConnectActionServerObject server = (ConnectActionServerObject) clientOrServer;
- server.send(obj);
- server.rec();
- } else {
- throw new ClassNotFoundException();
- }
+ /**
+ * Create a {@link Progress} that will forward its progress over the
+ * network.
+ *
+ * @param action
+ * the {@link ConnectActionServerObject} to use to forward it
+ *
+ * @return the {@link Progress}
+ */
+ private static Progress createPgForwarder(
+ final ConnectActionServerObject action) {
+ final Progress pg = new Progress();
+ final Integer[] p = new Integer[] { -1, -1, -1 };
+ pg.addProgressListener(new ProgressListener() {
+ @Override
+ public void progress(Progress progress, String name) {
+ int min = pg.getMin();
+ int max = pg.getMax();
+ int relativeProgress = min
+ + (int) Math.round(pg.getRelativeProgress()
+ * (max - min));
+
+ // Do not re-send the same value twice over the wire
+ if (p[0] != min || p[1] != max || p[2] != relativeProgress) {
+ p[0] = min;
+ p[1] = max;
+ p[2] = relativeProgress;
+
+ try {
+ action.send(new Integer[] { min, max, relativeProgress });
+ action.rec();
+ } catch (Exception e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+ }
+ });
+
+ return pg;