tn5250j/src/org/tn5250j/framework/tn5250 Screen5250.java,1.15,1.16 Stream5250.java,1.3,1.4 tnvt.java,1.15,1.16 ScreenPlanes.java,1.10,1.11 DataStreamQueue.java,1.3,1.4 DataStreamProducer.java,1.3,1.4

"Kenneth J. Pouncey" <[email protected]> Fri, 08 Jul 2005 06:16:27 +0000
Newsgroups gmane.comp.java.tn5250j.cvs
Message-ID <[email protected]>
Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28818/src/org/tn5250j/framework/tn5250

Modified Files:
	Screen5250.java Stream5250.java tnvt.java ScreenPlanes.java 
	DataStreamQueue.java DataStreamProducer.java 
Log Message:
Internal changes to reduce the number of objects created

Index: DataStreamProducer.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/DataStreamProducer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DataStreamProducer.java	16 Jun 2005 04:41:18 -0000	1.3
--- DataStreamProducer.java	8 Jul 2005 06:16:25 -0000	1.4
***************
*** 141,145 ****
  
              System.arraycopy(abyte0, i, abyte1, 0, j + 2);
!             dsq.put(new Stream5250(abyte1));
              if(abyte0.length > abyte1.length + i)
                  loadStream(abyte0, i + j + 2);
--- 141,146 ----
  
              System.arraycopy(abyte0, i, abyte1, 0, j + 2);
! //            dsq.put(new Stream5250(abyte1));
!             dsq.put(abyte1);
              if(abyte0.length > abyte1.length + i)
                  loadStream(abyte0, i + j + 2);
***************
*** 164,169 ****
        int j = -1;
        int i = 0;
! 
        while(!done) {
           i = bin.read();
  
--- 165,171 ----
        int j = -1;
        int i = 0;
!       
        while(!done) {
+          
           i = bin.read();
  

Index: DataStreamQueue.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/DataStreamQueue.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** DataStreamQueue.java	16 Jun 2005 04:41:18 -0000	1.3
--- DataStreamQueue.java	8 Jul 2005 06:16:25 -0000	1.4
***************
*** 49,54 ****
--- 49,107 ----
           }
  
+          //  Moved to the put routine.
+ //         /**
+ //          * @todo here is the throttling code to look at
+ //          *
+ //          * just something here to try.  OK it works but we need to be a little
+ //          *     more intelligent with the throttling.
+ //          */
+ //         if (vector.size() >= 20) {
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            vector.remove(0);
+ //            System.out.println(vector.size());
+ //         }
+             // we have the lock and state we're seeking
+          return vector.remove(0);
+       }
+    }
+ 
+    public boolean isEmpty() {
+ 
+       return vector.isEmpty();
+    }
+ 
+    public void clear() {
+ 
+       synchronized (lock) {
+          vector.clear();
+          lock.notifyAll();
+       }
+ 
+    }
+ 
+    public void put(Object o) {
+       synchronized (lock) {
+ 
           /**
            * @todo here is the throttling code to look at
+           * 
+           * I moved this from the get method to see what the difference would be.
+           * So far it works more reliably as a throttle in my opinion.
            *
            * just something here to try.  OK it works but we need to be a little
***************
*** 76,103 ****
  //            System.out.println(vector.size());
           }
!             // we have the lock and state we're seeking
!          return vector.remove(0);
!       }
!    }
! 
!    public boolean isEmpty() {
! 
!       return vector.isEmpty();
!    }
! 
!    public void clear() {
! 
!       synchronized (lock) {
!          vector.clear();
!          lock.notifyAll();
!       }
! 
!    }
! 
!    public void put(Object o) {
!       synchronized (lock) {
           vector.addElement(o);
! //         if (vector.size() > 5)
! //            System.out.println(vector.size());
           // tell waiting threads to wake up
           lock.notifyAll();
--- 129,135 ----
  //            System.out.println(vector.size());
           }
!             
           vector.addElement(o);
! 
           // tell waiting threads to wake up
           lock.notifyAll();

Index: tnvt.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/tnvt.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** tnvt.java	17 Jun 2005 04:42:40 -0000	1.15
--- tnvt.java	8 Jul 2005 06:16:24 -0000	1.16
***************
*** 273,277 ****
  			pthread = new Thread(producer);
  			//         pthread.setPriority(pthread.MIN_PRIORITY);
! 			pthread.setPriority(Thread.NORM_PRIORITY / 2);
  			pthread.start();
  
--- 273,278 ----
  			pthread = new Thread(producer);
  			//         pthread.setPriority(pthread.MIN_PRIORITY);
! 			pthread.setPriority(Thread.NORM_PRIORITY);
! //			pthread.setPriority(Thread.NORM_PRIORITY / 2);
  			pthread.start();
  
***************
*** 1017,1024 ****
  			sfParser = new WTDSFParser(this);
  
  		while (keepTrucking) {
  
  			try {
! 				bk = (Stream5250) dsq.get();
  			} catch (InterruptedException ie) {
  				log.warn("   vt thread interrupted and stopping ");
--- 1018,1028 ----
  			sfParser = new WTDSFParser(this);
  
+ 		bk = new Stream5250();
+ 		
  		while (keepTrucking) {
  
  			try {
! //				bk = (Stream5250) dsq.get();
! 				bk.initialize((byte[]) dsq.get());
  			} catch (InterruptedException ie) {
  				log.warn("   vt thread interrupted and stopping ");
***************
*** 1143,1147 ****
  				screen52.updateDirty();
  //				controller.validate();
! 				log.debug("update dirty");
  			} catch (Exception exd) {
  				log.warn(" tnvt.run: " + exd.getMessage());
--- 1147,1151 ----
  				screen52.updateDirty();
  //				controller.validate();
! //				log.debug("update dirty");
  			} catch (Exception exd) {
  				log.warn(" tnvt.run: " + exd.getMessage());
***************
*** 1468,1474 ****
  			int rows = bk.getNextByte() & 0xff;
  			int cols = bk.getNextByte() & 0xff;
! 			int pos = bk.getNextByte() << 8 & 0xff00;
  			pos |= bk.getNextByte() & 0xff;
! 			int hPos = bk.getNextByte() << 8 & 0xff00;
  			hPos |= bk.getNextByte() & 0xff;
  			if (rows != screen52.getRows())
--- 1472,1478 ----
  			int rows = bk.getNextByte() & 0xff;
  			int cols = bk.getNextByte() & 0xff;
! 			int pos = bk.getNextByte() << 8 & 0xff00; // current position
  			pos |= bk.getNextByte() & 0xff;
! 			int hPos = bk.getNextByte() << 8 & 0xff00; // home position
  			hPos |= bk.getNextByte() & 0xff;
  			if (rows != screen52.getRows())
***************
*** 1576,1586 ****
  			}
  
! 			screen52.restoreScreen(); // display the screen
! 			screen52.setPendingInsert(true, screen52.getRow(pos), screen52
! 					.getCol(pos));
! 			screen52.goto_XY(pos);
! 			screen52.isInField();
  			if (screen52.isUsingGuiInterface())
  				screen52.drawFields();
  		} catch (Exception e) {
  			log.warn("error restoring screen " + which + " with "
--- 1580,1602 ----
  			}
  
! 			//  Redraw the gui fields if we are in gui mode
  			if (screen52.isUsingGuiInterface())
  				screen52.drawFields();
+ 
+ 			screen52.restoreScreen(); // display the screen
+ 			
+ 			//  The position was saved with currentPos which 1,1 offset of the
+ 			//     screen position.
+ 			//  The setPendingInsert is the where the cursor position will be 
+ 			//  displayed after the restore.
+ 			screen52.setPendingInsert(true, screen52.getRow(pos + cols), screen52
+ 					.getCol(pos + cols));
+ 			//  We need to offset the pos by -1 since the position is 1,1 based
+ 			//    and the goto_XY is 0,0 based.
+ 			screen52.goto_XY(pos - 1);
+ 			screen52.isInField();
+ //			//  Redraw the gui fields if we are in gui mode
+ //			if (screen52.isUsingGuiInterface())
+ //				screen52.drawFields();
  		} catch (Exception e) {
  			log.warn("error restoring screen " + which + " with "

Index: Screen5250.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/Screen5250.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** Screen5250.java	14 Jun 2005 06:10:51 -0000	1.15
--- Screen5250.java	8 Jul 2005 06:16:23 -0000	1.16
***************
*** 1962,1971 ****
        }
  
        // get the number of characters to the right
        int count = (end - sf.startPos()) - sf.getKeyPos(pos);
  
        if (count == 0 && sf.isFER()) {
!          mdt = true;
!          return mdt;
        }
  
--- 1962,1980 ----
        }
  
+       // save off the current pos of the field for checking field exit required
+       //   positioning.  the getKeyPos resets this information so it is useless
+       //   for comparing if we are positioned passed the end of field.
+       //   Maybe this should be changed to not update the current cursor position
+       //   of the field.
+       int currentPos = sf.getCurrentPos();
+       
        // get the number of characters to the right
        int count = (end - sf.startPos()) - sf.getKeyPos(pos);
  
        if (count == 0 && sf.isFER()) {
!          if (currentPos > sf.endPos()) {
!             mdt = true;
!             return mdt;
!          }
        }
  
***************
*** 2176,2180 ****
  	public int getCurrentPos() {
  
! 		return lastPos + numCols + 1;
  
  	}
--- 2185,2190 ----
  	public int getCurrentPos() {
  
! //		return lastPos + numCols + 1;
! 		return lastPos + 1;
  
  	}
***************
*** 2189,2193 ****
      * </p>
      * <p>
!     * 0010: 00 36 E9 1C 40 00 80 06 9B F9 C1 A8 33 58 C0 A8 [email protected]..
      * </p>
      * <p>
--- 2199,2203 ----
      * </p>
      * <p>
!     * 0010: 00 36 E9 1C 40 00 80 06 9B F9 C1 A8 33 58 C0 A8 [email protected]..
      * </p>
      * <p>
***************
*** 2276,2288 ****
  		//    just plain move the cursor if the key was to do that.
  
  		if (feError) {
  			feError = false;
! 			screenFields.getCurrentField().changePos(-1);
  
! 			if (screenFields.getCurrentField() != null
! 					&& screenFields.getCurrentField().isFER()
! 					&& screenFields.getCurrentFieldPos() - 1 == pos) {
  			}
  		} else {
  			goto_XY(pos);
  		}
--- 2286,2314 ----
  		//    just plain move the cursor if the key was to do that.
  
+ 		ScreenField sf = screenFields.getCurrentField();
  		if (feError) {
  			feError = false;
! 			sf.changePos(-1);
  
! 			if (sf != null
! 					&& sf.isFER()
! 					&& sf.getCurrentPos() - 1 == pos) {
! 			   
  			}
  		} else {
+ 			if (sf != null
+ 					&& sf.isFER()){
+ 			   if ((sf.getCurrentPos()
+ 			         > sf.endPos())) {
+ 			      if (sf.withinField(pos)) {
+ 			         sf.getKeyPos(pos);
+ 			         return;
+ 			      }
+ 			      else {
+ 			         sf.getKeyPos(sf.endPos());
+ 			      }
+ 			   }
+ 			}
+ 		   
  			goto_XY(pos);
  		}
***************
*** 3460,3464 ****
  			}
  		}
!   		updateDirty();
  	}
  
--- 3486,3491 ----
  			}
  		}
! 		
!   		//updateDirty();
  	}
  
***************
*** 3535,3539 ****
  	protected void setChar(int cByte) {
  
! 		if (cByte > 0 && cByte < ' ') {
  			planes.setScreenCharAndAttr(lastPos, (char) 0x00, 33, false);
  			setDirty(lastPos);
--- 3562,3566 ----
  	protected void setChar(int cByte) {
  
! 		if (cByte > 0 && (char)cByte < ' ') {
  			planes.setScreenCharAndAttr(lastPos, (char) 0x00, 33, false);
  			setDirty(lastPos);

Index: ScreenPlanes.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/ScreenPlanes.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** ScreenPlanes.java	16 Jun 2005 04:41:18 -0000	1.10
--- ScreenPlanes.java	8 Jul 2005 06:16:24 -0000	1.11
***************
*** 437,441 ****
     protected synchronized char[] getPlaneData(int from, int to, int plane) {
  
!       int len = to - from;
  
        char[] planeChars = new char[len + 1];
--- 437,441 ----
     protected synchronized char[] getPlaneData(int from, int to, int plane) {
  
!       int len = (to - from);
  
        char[] planeChars = new char[len + 1];

Index: Stream5250.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/framework/tn5250/Stream5250.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Stream5250.java	16 Jun 2005 04:41:18 -0000	1.3
--- Stream5250.java	8 Jul 2005 06:16:24 -0000	1.4
***************
*** 43,46 ****
--- 43,71 ----
      }
  
+     public Stream5250() {
+        buffer = null;
+        streamSize = 0;
+        opCode = 0;
+        dataStart = 0;
+        pos = dataStart;
+    }
+ 
+     /**
+      * This method takes a byte array and initializes the object information
+      *    to be used.
+      * 
+      * @param abyte0
+      */
+     public void initialize(byte abyte0[]) {
+        
+      buffer = abyte0;
+      // size without end of record 0xFF 0xEF
+      streamSize = (abyte0[0] & 0xff) << 8 | abyte0[1] & 0xff;
+      opCode = abyte0[9];
+      dataStart = 6 + abyte0[6];
+      pos = dataStart;
+        
+     }
+     
      public final int getOpCode() {
          return opCode;
***************
*** 49,53 ****
      public final byte getNextByte()
          throws Exception  {
!         if(pos > buffer.length)
              throw new Exception("Buffer length exceeded: " + pos);
          else
--- 74,78 ----
      public final byte getNextByte()
          throws Exception  {
!         if(buffer == null || pos > buffer.length)
              throw new Exception("Buffer length exceeded: " + pos);
          else
***************
*** 77,81 ****
          throws Exception  {
  
!         if((pos + off ) > buffer.length)
              throw new Exception("Buffer length exceeded: " + pos);
          else
--- 102,106 ----
          throws Exception  {
  
!         if(buffer == null || (pos + off ) > buffer.length)
              throw new Exception("Buffer length exceeded: " + pos);
          else



-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP, 
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar