Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 74:f1938dd3b518
don't heap space error.
author | oc |
---|---|
date | Mon, 28 Apr 2014 18:25:23 +0900 |
parents | 35f761bcb12c |
children | bbee0f101911 |
files | .classpath .settings/org.eclipse.jdt.core.prefs build.gradle src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java |
diffstat | 8 files changed, 86 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Fri Apr 18 11:17:34 2014 +0900 +++ b/.classpath Mon Apr 28 18:25:23 2014 +0900 @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> + <classpathentry kind="output" path="bin"/> <classpathentry kind="src" path="src/main/java"/> <classpathentry kind="src" path="src/viewer_swing/java"/> <classpathentry kind="src" path="src/viewer_swing/resources"/> - <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="lib" path="src/libs/jsch-0.1.50.jar"/> - <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> - <classpathentry kind="output" path="bin"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/> + <classpathentry kind="lib" path="/Users/one/Documents/workspace/TreeVNC/src/libs/jsch-0.1.50.jar" exported="true"/> + <classpathentry kind="lib" path="/Applications/eclipse/Eclipse.app/Contents/MacOS/unresolved dependency - junit junit 4.+" exported="true"/> </classpath>
--- a/.settings/org.eclipse.jdt.core.prefs Fri Apr 18 11:17:34 2014 +0900 +++ b/.settings/org.eclipse.jdt.core.prefs Mon Apr 28 18:25:23 2014 +0900 @@ -1,11 +1,13 @@ +# +#Mon Apr 28 16:04:44 JST 2014 +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.debug.lineNumber=generate eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.source=1.6 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7
--- a/build.gradle Fri Apr 18 11:17:34 2014 +0900 +++ b/build.gradle Mon Apr 28 18:25:23 2014 +0900 @@ -76,14 +76,14 @@ archives noSshJar } -//uploadArchives { -// repositories { -// add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) { -// addArtifactPattern("$projectDir/dist/${project.baseName}-${project.version}/[artifact].[ext]") -// } -// } -// uploadDescriptor = false -//} +uploadArchives { + repositories { + add(new org.apache.ivy.plugins.resolver.FileSystemResolver()) { + addArtifactPattern("$projectDir/dist/${project.baseName}-${project.version}/[artifact].[ext]") + } + } + uploadDescriptor = false +} task dist(dependsOn: uploadArchives)
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Mon Apr 28 18:25:23 2014 +0900 @@ -1,5 +1,6 @@ package jp.ac.u_ryukyu.treevnc; +import java.nio.ByteBuffer; import java.util.concurrent.CountDownLatch; public class MulticastQueue<T> @@ -11,7 +12,40 @@ { tail = new Node<T>(null); } + + /** + * @param size + * @return + * + * try to allocate byteBuffer. + * wait until heap is available. + * + * + */ + public ByteBuffer allocate(int size) + { + ByteBuffer b=null; + while(true){ + try{ + b = ByteBuffer.allocate(size); + }catch(OutOfMemoryError e){ + System.err.println("multicastqueue : wait for heap : " + e); + } + if(b!=null){ + break; + } + try { + wait(); + } catch (InterruptedException e) { + } + } + return b; + } + public synchronized void heapAvailable() { + notifyAll(); + } + public synchronized void put(T item) { Node<T> next = new Node<T>(item); @@ -43,7 +77,6 @@ }catch(InterruptedException _e){ continue; } -// item = node.getItem(); item = next.getItem(); node = next; } while ( item == null);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Apr 28 18:25:23 2014 +0900 @@ -182,6 +182,8 @@ os.write(b.array(), b.position(), b.limit()); } os.flush(); + bufs = null; + multicastqueue.heapAvailable(); } }; clients++;
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Mon Apr 28 18:25:23 2014 +0900 @@ -226,7 +226,7 @@ public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { int len = 0; - ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); + ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); while (inputIndex < inputs.size()) { ByteBuffer b1 = inputs.get(inputIndex++); deflater.setInput(b1.array(), b1.position(), b1.remaining()); @@ -249,7 +249,7 @@ if (c1.remaining() == 0) { c1.flip(); outputs.addLast(c1); - c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); + c1 = multicastqueue.allocate(INFLATE_BUFSIZE); } } } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished()); @@ -277,7 +277,7 @@ int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize) throws DataFormatException { int len = 0; - ByteBuffer buf = ByteBuffer.allocate(bufSize); + ByteBuffer buf = multicastqueue.allocate(bufSize); while (inputIndex < inputs.size()) { ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(), input.position(), input.limit()); @@ -293,7 +293,7 @@ if (buf.remaining() == 0) { buf.flip(); outputs.addLast(buf); - buf = ByteBuffer.allocate(bufSize); + buf = multicastqueue.allocate(bufSize); } } } while (!inflater.needsInput()); @@ -308,8 +308,8 @@ public void readSendData(int dataLen, Reader reader) throws TransportException { LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); - ByteBuffer header = ByteBuffer.allocate(16); - ByteBuffer serial = ByteBuffer.allocate(8); + ByteBuffer header = multicastqueue.allocate(16); + ByteBuffer serial = multicastqueue.allocate(8); reader.mark(dataLen+8); // +8 is serialnum reader.readBytes(serial.array(),0,8); serial.limit(8); @@ -321,10 +321,10 @@ || encoding == EncodingType.ZLIB.getId()) { // ZRLEE is // already // recompressed - ByteBuffer len = ByteBuffer.allocate(4); + ByteBuffer len = multicastqueue.allocate(4); reader.readBytes(len.array(), 0, 4); len.limit(4); - ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); + ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); reader.readBytes(inputData.array(), 0, inputData.capacity()); inputData.limit(dataLen - 20); LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); @@ -341,7 +341,7 @@ unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE); // dump32(inputs); int len2 = zip(nDeflater, out, 0, bufs); - ByteBuffer blen = ByteBuffer.allocate(4); + ByteBuffer blen = multicastqueue.allocate(4); blen.putInt(len2); blen.flip(); bufs.addFirst(blen); @@ -360,7 +360,7 @@ bufs.add(serial); bufs.add(header); if (dataLen > 16) { - ByteBuffer b = ByteBuffer.allocate(dataLen - 16); + ByteBuffer b = multicastqueue.allocate(dataLen - 16); reader.readBytes(b.array(), 0, dataLen - 16); b.limit(dataLen - 16); bufs.add(b); @@ -396,7 +396,7 @@ @Override public void readCheckDelay(Reader reader) throws TransportException { - ByteBuffer buf = ByteBuffer.allocate(24); + ByteBuffer buf = multicastqueue.allocate(24); reader.readBytes(buf.array(), 0, 24); LinkedList<ByteBuffer> sendData = new LinkedList<ByteBuffer>();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Mon Apr 28 18:25:23 2014 +0900 @@ -165,7 +165,7 @@ public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { int len = 0; - ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); + ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); while (inputIndex < inputs.size()) { ByteBuffer b1 = inputs.get(inputIndex++); deflater.setInput(b1.array(), b1.position(), b1.remaining()); @@ -188,7 +188,7 @@ if (c1.remaining() == 0) { c1.flip(); outputs.addLast(c1); - c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); + c1 = multicastqueue.allocate(INFLATE_BUFSIZE); } } } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished()); @@ -216,7 +216,7 @@ int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize) throws DataFormatException { int len = 0; - ByteBuffer buf = ByteBuffer.allocate(bufSize); + ByteBuffer buf = multicastqueue.allocate(bufSize); while (inputIndex < inputs.size()) { ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(), input.position(), input.limit()); @@ -232,7 +232,7 @@ if (buf.remaining() == 0) { buf.flip(); outputs.addLast(buf); - buf = ByteBuffer.allocate(bufSize); + buf = multicastqueue.allocate(bufSize); } } } while (!inflater.needsInput()); @@ -270,7 +270,7 @@ */ public void readSendData(int dataLen, Reader is) throws TransportException { LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); - ByteBuffer header = ByteBuffer.allocate(16); + ByteBuffer header = multicastqueue.allocate(16); is.readBytes(header.array(), 0, 16); header.limit(16); if (header.get(0) == FramebufferUpdate) { @@ -279,10 +279,10 @@ || encoding == EncodingType.ZLIB.getId()) { // ZRLEE is // already // recompressed - ByteBuffer len = ByteBuffer.allocate(4); + ByteBuffer len = multicastqueue.allocate(4); is.readBytes(len.array(), 0, 4); len.limit(4); - ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); + ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); is.readBytes(inputData.array(), 0, inputData.capacity()); // System.out.println(dataLen); @@ -303,47 +303,33 @@ try { unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE); len2 = zip(nDeflater, out, 0, bufs); + out = null; + multicastqueue.heapAvailable(); } catch (DataFormatException e) { throw new TransportException(e); } catch (IOException e) { throw new TransportException(e); } - //if(dataLen<=64000) - ByteBuffer blen = ByteBuffer.allocate(4); + + ByteBuffer blen = multicastqueue.allocate(4); blen.putInt(len2); blen.flip(); bufs.addFirst(blen); bufs.addFirst(header); - ByteBuffer serialNum = ByteBuffer.allocate(8); + ByteBuffer serialNum = multicastqueue.allocate(8); serialNum.putLong(counter++); serialNum.flip(); bufs.addFirst(serialNum); - /* - if(i++%50 == 0) { - LinkedList<ByteBuffer> check = new LinkedList<ByteBuffer>(); - ByteBuffer test = ByteBuffer.allocate(8); - ByteBuffer header2 = ByteBuffer.allocate(16); - header2.limit(16); - header2.put((byte)11); - header2.putInt(12, EncodingType.ZRLEE.getId()); - header2.position(0); - test.putLong(System.currentTimeMillis()); - test.flip(); - check.addFirst(test); - check.addFirst(header2); - multicastqueue.put(check); - } - */ multicastqueue.put(bufs); - // is.reset(); + return; } bufs.add(header); if (dataLen > 16) { - ByteBuffer b = ByteBuffer.allocate(dataLen - 16); + ByteBuffer b = multicastqueue.allocate(dataLen - 16); is.readBytes(b.array(), 0, dataLen - 16); b.limit(dataLen - 16); bufs.add(b);
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Fri Apr 18 11:17:34 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeViewer.java Mon Apr 28 18:25:23 2014 +0900 @@ -66,9 +66,9 @@ + "-v: VNCViewer\n" + "-r: TreeVNCProxy for RemoteHost. you should input parameter host and port\n" + "--host hostname: set host name\n" - + "--retina: TreeVNC proxy for retina.this mode can select screen range.\n" - + "--width w: set display width\n" - + "--height h: set display height\n"); + + "--retina: TreeVNC proxy for retina.this mode can select screen range." + + "--width w: set display width" + + "--height h: set display height"); } } }