You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2014/03/29 23:31:58 UTC
svn commit: r1583081 - in
/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench:
ClientHelper.java LoggingInputStream.java model/ClientModel.java
Author: fmui
Date: Sat Mar 29 22:31:58 2014
New Revision: 1583081
URL: http://svn.apache.org/r1583081
Log:
Workbench: added logging to up and downloads
Added:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoggingInputStream.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java?rev=1583081&r1=1583080&r2=1583081&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ClientHelper.java Sat Mar 29 22:31:58 2014
@@ -350,7 +350,7 @@ public final class ClientHelper {
OutputStream out = null;
try {
out = new FileOutputStream(file);
- IOUtils.copy(in, out, BUFFER_SIZE);
+ IOUtils.copy(new LoggingInputStream(in, file.getName()), out, BUFFER_SIZE);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
Added: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoggingInputStream.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoggingInputStream.java?rev=1583081&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoggingInputStream.java (added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/LoggingInputStream.java Sat Mar 29 22:31:58 2014
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.workbench;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.NumberFormat;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LoggingInputStream extends InputStream {
+
+ private static final Logger LOG = LoggerFactory.getLogger(LoggingInputStream.class);
+
+ private final InputStream stream;
+ private final String desc;
+ private long marked;
+ private long count = 0;
+ private long startTimestamp = -1;
+ private long endTimestamp = -1;
+
+ public LoggingInputStream(InputStream stream, String desc) {
+ super();
+ this.stream = stream;
+ this.desc = desc;
+ }
+
+ @Override
+ public int available() throws IOException {
+ return stream.available();
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ stream.mark(readlimit);
+ marked = count;
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("{}: mark", desc);
+ }
+ }
+
+ @Override
+ public boolean markSupported() {
+ return stream.markSupported();
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ stream.reset();
+ count = marked;
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("{}: reset", desc);
+ }
+ }
+
+ protected void count(long len) {
+ if (startTimestamp < 0) {
+ startTimestamp = System.currentTimeMillis();
+ LOG.info("{}: started streaming", desc);
+ }
+ if (len == -1 && endTimestamp == -1) {
+ endTimestamp = System.currentTimeMillis();
+ long time = (endTimestamp - startTimestamp);
+ long kibPerSec = (time < 1 ? -1L : (long) (((double) count / 1024) / ((double) time / 1000)));
+
+ NumberFormat nf = NumberFormat.getInstance();
+ LOG.info("{}: streamed {} bytes in {} ms, {} KiB/sec", desc, nf.format(count), nf.format(time),
+ nf.format(kibPerSec));
+ } else {
+ count += len;
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ int b = stream.read();
+ count(b == -1 ? -1 : 1);
+
+ if (b != -1 && LOG.isTraceEnabled()) {
+ LOG.trace("{}: read {} bytes", desc, count);
+ }
+
+ return b;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int rb = stream.read(b, off, len);
+ count(rb);
+
+ if (rb != -1 && LOG.isTraceEnabled()) {
+ LOG.trace("{}: read {} bytes", desc, count);
+ }
+
+ return rb;
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ int rb = stream.read(b);
+ count(rb);
+
+ if (rb != -1 && LOG.isTraceEnabled()) {
+ LOG.trace("{}: read {} bytes", desc, count);
+ }
+
+ return rb;
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ long len = super.skip(n);
+ count(len);
+
+ if (len > 0 && LOG.isTraceEnabled()) {
+ LOG.trace("{}: read {} bytes", desc, count);
+ }
+
+ return len;
+ }
+
+ @Override
+ public void close() throws IOException {
+ super.close();
+
+ if (LOG.isDebugEnabled()) {
+ LOG.info("{}: stream closed", desc);
+ }
+ }
+}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java?rev=1583081&r1=1583080&r2=1583081&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java Sat Mar 29 22:31:58 2014
@@ -55,6 +55,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.commons.impl.MimeTypes;
+import org.apache.chemistry.opencmis.workbench.LoggingInputStream;
import org.apache.chemistry.opencmis.workbench.RandomInputStream;
public class ClientModel {
@@ -254,7 +255,8 @@ public class ClientModel {
ContentStream content = null;
if ((filename != null) && (filename.length() > 0)) {
File file = new File(filename);
- InputStream stream = new BufferedInputStream(new FileInputStream(file));
+ InputStream stream = new LoggingInputStream(new BufferedInputStream(new FileInputStream(file)),
+ file.getName());
content = clientSession.getSession().getObjectFactory()
.createContentStream(file.getName(), file.length(), MimeTypes.getMIMEType(file), stream);
@@ -285,8 +287,11 @@ public class ClientModel {
}
public ContentStream createContentStream(String name, long length, long seed) {
- return clientSession.getSession().getObjectFactory()
- .createContentStream(name, length, "application/octet-stream", new RandomInputStream(length, seed));
+ return clientSession
+ .getSession()
+ .getObjectFactory()
+ .createContentStream(name, length, "application/octet-stream",
+ new LoggingInputStream(new RandomInputStream(length, seed), name + " (random)"));
}
public synchronized ObjectId createDocument(String name, String type, Map<String, Object> additionalProperties,