From 87597393fedecdbd70b52a229937c87120ed6713 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Fri, 15 Oct 2010 14:03:10 +0000 Subject: [PATCH] removed recycling of event object, made events immutable so jvm can optimize things better. Tested roughly with sampler, 1Gb random file and visualvm: effect very small, negligible if tracking is used (paint phase creates a lot more objects). Server on a separate hardware + several clients might cause slightly different results, but I suspect that the difference would still be negligible. svn changeset:15566/svn branch:6.5 --- .../server/AbstractCommunicationManager.java | 19 +++++--------- .../gwt/server/AbstractReceivingEvent.java | 25 ++++++++----------- .../gwt/server/ReceivingEndedEventImpl.java | 4 +-- .../gwt/server/ReceivingFailedEventImpl.java | 9 ++++--- .../server/ReceivingProgressedEventImpl.java | 9 ++++--- .../gwt/server/ReceivingStartedEventImpl.java | 4 +-- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index e621e27cbe..5bff9619a7 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -573,6 +573,7 @@ public abstract class AbstractCommunicationManager implements final Application application = getApplication(); OutputStream out = null; + int totalBytes = 0; try { boolean listenProgress; synchronized (application) { @@ -595,10 +596,6 @@ public abstract class AbstractCommunicationManager implements final byte buffer[] = new byte[MAX_UPLOAD_BUFFER_SIZE]; int bytesReadToBuffer = 0; - int totalBytes = 0; - ReceivingProgressedEventImpl progressEvent = new ReceivingProgressedEventImpl( - receiver, filename, type, contentLength); - while ((bytesReadToBuffer = in.read(buffer)) > 0) { out.write(buffer, 0, bytesReadToBuffer); totalBytes += bytesReadToBuffer; @@ -606,13 +603,9 @@ public abstract class AbstractCommunicationManager implements // update progress if listener set and contentLength // received synchronized (application) { - /* - * Note, we are reusing the same progress event, not to - * pollute VM with lots of objects. This might not help - * though if the end user aggressively updates UI on - * each onProgress. - */ - progressEvent.setBytesReceived(totalBytes); + ReceivingProgressedEventImpl progressEvent = new ReceivingProgressedEventImpl( + receiver, filename, type, contentLength, + totalBytes); controller.onProgress(progressEvent); } } @@ -638,7 +631,7 @@ public abstract class AbstractCommunicationManager implements // NOP } ReceivingFailedEvent event = new ReceivingFailedEventImpl(receiver, - filename, type, contentLength, e); + filename, type, contentLength, totalBytes, e); synchronized (application) { controller.uploadFailed(event); } @@ -647,7 +640,7 @@ public abstract class AbstractCommunicationManager implements } catch (final Exception e) { synchronized (application) { ReceivingFailedEvent event = new ReceivingFailedEventImpl( - receiver, filename, type, contentLength, e); + receiver, filename, type, contentLength, totalBytes, e); synchronized (application) { controller.uploadFailed(event); } diff --git a/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java b/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java index 2e84538e92..a3ada4ea53 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractReceivingEvent.java @@ -10,40 +10,37 @@ import com.vaadin.terminal.ReceiverOwner.ReceivingEvent; abstract class AbstractReceivingEvent implements ReceivingEvent { private final String type; private final String filename; - private Receiver receiver; - private long contentLength; - private long bytesReceived; + private final Receiver receiver; + private final long contentLength; + private final long bytesReceived; - public String getFileName() { + public final String getFileName() { return filename; } - public String getMimeType() { + public final String getMimeType() { return type; } - public AbstractReceivingEvent(Receiver receiver, String filename, - String type, long length) { + protected AbstractReceivingEvent(Receiver receiver, String filename, + String type, long length, long bytesReceived) { this.receiver = receiver; this.filename = filename; this.type = type; contentLength = length; + this.bytesReceived = bytesReceived; } - public Receiver getReceiver() { + public final Receiver getReceiver() { return receiver; } - public long getContentLength() { + public final long getContentLength() { return contentLength; } - public long getBytesReceived() { + public final long getBytesReceived() { return bytesReceived; } - void setBytesReceived(long bytesReceived) { - this.bytesReceived = bytesReceived; - } - } diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java index e5519abf56..06609f058e 100644 --- a/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java +++ b/src/com/vaadin/terminal/gwt/server/ReceivingEndedEventImpl.java @@ -4,12 +4,12 @@ import com.vaadin.terminal.Receiver; import com.vaadin.terminal.ReceiverOwner.ReceivingEndedEvent; @SuppressWarnings("serial") -class ReceivingEndedEventImpl extends AbstractReceivingEvent implements +final class ReceivingEndedEventImpl extends AbstractReceivingEvent implements ReceivingEndedEvent { public ReceivingEndedEventImpl(Receiver receiver, String filename, String type, long totalBytes) { - super(receiver, filename, type, totalBytes); + super(receiver, filename, type, totalBytes, totalBytes); } } diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java index f57675af65..c732e69cc9 100644 --- a/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java +++ b/src/com/vaadin/terminal/gwt/server/ReceivingFailedEventImpl.java @@ -4,18 +4,19 @@ import com.vaadin.terminal.Receiver; import com.vaadin.terminal.ReceiverOwner.ReceivingFailedEvent; @SuppressWarnings("serial") -class ReceivingFailedEventImpl extends AbstractReceivingEvent implements +final class ReceivingFailedEventImpl extends AbstractReceivingEvent implements ReceivingFailedEvent { private final Exception exception; public ReceivingFailedEventImpl(Receiver receiver, final String filename, - final String type, long contentLength, final Exception exception) { - super(receiver, filename, type, contentLength); + final String type, long contentLength, long bytesReceived, + final Exception exception) { + super(receiver, filename, type, contentLength, bytesReceived); this.exception = exception; } - public Exception getException() { + public final Exception getException() { return exception; } diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java index a098cf0be9..f28f0ad453 100644 --- a/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java +++ b/src/com/vaadin/terminal/gwt/server/ReceivingProgressedEventImpl.java @@ -4,12 +4,13 @@ import com.vaadin.terminal.Receiver; import com.vaadin.terminal.ReceiverOwner.ReceivingProgressedEvent; @SuppressWarnings("serial") -class ReceivingProgressedEventImpl extends AbstractReceivingEvent implements - ReceivingProgressedEvent { +final class ReceivingProgressedEventImpl extends AbstractReceivingEvent + implements ReceivingProgressedEvent { public ReceivingProgressedEventImpl(Receiver receiver, - final String filename, final String type, long contentLength) { - super(receiver, filename, type, contentLength); + final String filename, final String type, long contentLength, + long bytesReceived) { + super(receiver, filename, type, contentLength, bytesReceived); } } diff --git a/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java b/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java index 119d169bec..beb2ac8e25 100644 --- a/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java +++ b/src/com/vaadin/terminal/gwt/server/ReceivingStartedEventImpl.java @@ -4,12 +4,12 @@ import com.vaadin.terminal.Receiver; import com.vaadin.terminal.ReceiverOwner.ReceivingStartedEvent; @SuppressWarnings("serial") -class ReceivingStartedEventImpl extends AbstractReceivingEvent implements +final class ReceivingStartedEventImpl extends AbstractReceivingEvent implements ReceivingStartedEvent { public ReceivingStartedEventImpl(Receiver receiver, final String filename, final String type, long contentLength) { - super(receiver, filename, type, contentLength); + super(receiver, filename, type, contentLength, 0); } } -- 2.39.5