Changeset 58

Show
Ignore:
Timestamp:
07/31/08 12:48:30 (4 months ago)
Author:
jtang
Message:

Made Java functions synchronized (otherwise Bad Things (TM) happen).
Clean up of Java test programs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libsipc/bindings/java/com/tresys/sipc/Sipc.java

    r57 r58  
    8181         * the system IPC resource. 
    8282         */ 
    83         public void DestroyHandle() { 
     83        public synchronized void DestroyHandle() { 
    8484                this.Close(); 
    8585                sipcwrapper.sipc_unlink(key, ipc_type); 
     
    9292         *                      false otherwise 
    9393         */ 
    94         public boolean IsConnected() { 
     94        public synchronized boolean IsConnected() { 
    9595                return this.isConnected; 
    9696        } 
     
    100100         * effect if the handle is already in a disconnected state. 
    101101         */ 
    102         public void Close() { 
     102        public synchronized void Close() { 
    103103                if (isConnected) { 
    104104                        handle.close(); 
     
    114114         * implemented by all backends. 
    115115         */ 
    116         public void RecvDone() throws Exception {} 
     116        public synchronized void RecvDone() throws Exception {} 
    117117 
    118118        /** 
     
    125125         * read. 
    126126         */ 
    127         public byte[] ReadData() throws Exception { 
     127        public synchronized byte[] ReadData() throws Exception { 
    128128                if (isConnected) { 
    129129                        return handle.recv_data(); 
     
    142142         * @return  A reference to the IPC handle's internal data buffer. 
    143143         */ 
    144         public java.nio.ByteBuffer GetDataPtr() throws Exception { 
     144        public synchronized java.nio.ByteBuffer GetDataPtr() throws Exception { 
    145145                if (isConnected) { 
    146146                        /* cache the dataPtr, to avoid re-creating it for 
     
    166166         * @param len Length of the message to be sent. 
    167167         */ 
    168         public void SendData(int len) throws Exception { 
     168        public synchronized void SendData(int len) throws Exception { 
    169169                if (isConnected) { 
    170170                        java.nio.ByteBuffer b = GetDataPtr(); 
     
    185185         * connected state for this to succeed. 
    186186         */ 
    187         public void SendData() throws Exception { 
     187        public synchronized void SendData() throws Exception { 
    188188                if (isConnected) { 
    189189                        handle.send_data(dataPtr.limit()); 
     
    201201         * set the channel to not block when reading. 
    202202         */ 
    203         public void IOCtl(int request) throws Exception { 
     203        public synchronized void IOCtl(int request) throws Exception { 
    204204                if (isConnected) { 
    205205                        handle.ioctl(request); 
  • trunk/libsipc/bindings/java/com/tresys/sipc/SipcShm.java

    r54 r58  
    4747         * successfully received and handled. 
    4848         */ 
    49         public void RecvDone() throws Exception { 
     49        public synchronized void RecvDone() throws Exception { 
    5050                if (isConnected) { 
    5151                        handle.shm_recv_done(); 
  • trunk/libsipc/bindings/java/tests/run_tests.sh

    r52 r58  
    66fi 
    77JFLAGS='-cp ../libsipc-1.0.jar:. -Djava.library.path=..' 
     8 
     9MQ_TEST_FILE=Makefile 
     10SHM_TEST_FILE=../sipc_wrap.c 
    811 
    912set -e 
     
    1518 
    1619echo -n "  sending..." 
    17 ${JAVA} ${JFLAGS} MQ_Sender Makefile 
     20${JAVA} ${JFLAGS} MQ_Sender ${MQ_TEST_FILE} 
    1821echo " pass" 
    1922 
    2023echo -n "  reading..." 
    2124${JAVA} ${JFLAGS} MQ_Reader 
    22 diff Makefile out.dat || (echo " diff failed" ; exit 1) 
     25diff ${MQ_TEST_FILE} out.dat || (echo " diff failed" ; exit 1) 
    2326echo " pass" 
    2427 
    2528echo -n "  destroying..." 
    2629${JAVA} ${JFLAGS} MQ_Destroyer && echo " pass" 
    27  
     30exit 0 
    2831echo "Testing Shared Memory:" 
    2932 
     
    3235 
    3336echo "  sending (as a background process)..." 
    34 ${JAVA} ${JFLAGS} SHM_Sender ../sipc_wrap.c
     37${JAVA} ${JFLAGS} SHM_Sender ${SHM_TEST_FILE}
    3538 
    3639sleep 1 
     
    3942# because shm does not set the proper number of bytes read, truncate the 
    4043# output here 
    41 bytes=$(wc -c ../sipc_wrap.c | cut -f 1 -d ' ') 
     44bytes=$(wc -c ${SHM_TEST_FILE} | cut -f 1 -d ' ') 
    4245dd if=out.dat of=out.trimmed count=1 bs=${bytes} > /dev/null 2>&1 
    43 result=$(diff ../sipc_wrap.c out.trimmed) 
     46result=$(diff ${SHM_TEST_FILE} out.trimmed) 
    4447if test ${result}; then 
    4548  echo " diff failed"