Skip to content

Commit

Permalink
BZ941 Fix for rewrite on outputstream with large sizes/fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Jun 21, 2013
1 parent 8555b89 commit 8430901
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/REL_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ This Release
- Add fix for disconnect logic on bad connection (BZ947).
- Add fix for rootpoa creation with bad socket (BZ943).
- Add fix for non_existent (BZ953).
- Add fix for rewrite on OutputStream with large sizes (BZ941).
- POA
- Add fix for exception in interceptors breaking requestprocesor thread. (BZ946)
- Add fix for requestprocessor pooling. (BZ946)
Expand Down
43 changes: 31 additions & 12 deletions src/org/jacorb/orb/CDROutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public class CDROutputStream

/** deferredArrayQueue is initialized on demand in write_octet_array */
/* deferredArrayQueue is initialized on demand in write_octet_array */
private List deferredArrayQueue;
private List<DeferredWriteFrame> deferredArrayQueue;

private int deferredArrayQueueSize;

Expand Down Expand Up @@ -387,14 +387,14 @@ public void write( OutputStream out, int start, int length )
{
// find the first frame that falls within the current window,
// i.e. that need s to be written
next_frame = (DeferredWriteFrame)deferredArrayQueue.get( list_idx++ );
next_frame = deferredArrayQueue.get( list_idx++ );

// skip all frames beginning before the current start pos, but
// record their length
while( next_frame.write_pos < start && list_idx < deferredArrayQueue.size() )
{
skip_count += next_frame.length;
next_frame = (DeferredWriteFrame)deferredArrayQueue.get( list_idx++ );
next_frame = deferredArrayQueue.get( list_idx++ );
}

// skip
Expand Down Expand Up @@ -427,7 +427,7 @@ public void write( OutputStream out, int start, int length )
if( deferredArrayQueue != null &&
list_idx < deferredArrayQueue.size() )
{
next_frame = (DeferredWriteFrame)deferredArrayQueue.get( list_idx++ );
next_frame = deferredArrayQueue.get( list_idx++ );
if( next_frame.write_pos > start + length )
{
// unset, frame is beyond our current reach
Expand Down Expand Up @@ -640,7 +640,7 @@ public final void endEncapsulation()

/* restore index and encaps_start information and indirection maps */

EncapsInfo ei = (EncapsInfo)getEncapsStack().pop();
EncapsInfo ei = getEncapsStack().pop();
encaps_start = ei.start;
index = ei.index + encaps_size;
valueMap = ei.valueMap;
Expand Down Expand Up @@ -695,7 +695,7 @@ public final void increaseSize(final int amount)
}

/**
* Replace existing buffer by and new one and reset indices.
* Replace existing buffer by a new one and reset indices.
*
* @param b the new buffer
*/
Expand Down Expand Up @@ -1088,6 +1088,7 @@ public void write_fixed(BigDecimal value, short digits, short scale)
/**
* @deprecated
*/
@Deprecated
public void write_fixed(final java.math.BigDecimal value)
{
write_fixed(value, (short)-1, (short)-1);
Expand Down Expand Up @@ -1265,15 +1266,33 @@ public final void write_octet_array( final byte[] value,
{
if( value != null )
{
if( deferredArrayQueueSize > 0 && length > deferredArrayQueueSize )
if( ( deferredArrayQueueSize > 0 && length > deferredArrayQueueSize ) || deferred_writes > 0 )
{
if (deferredArrayQueue == null)
{
deferredArrayQueue = new ArrayList();
deferredArrayQueue = new ArrayList<DeferredWriteFrame>();
}
if (deferredArrayQueue.size() > 0)
{
// in case of rewrite, we remove deferred write frames
boolean remove = false;
for ( int list_idx = 0 ; list_idx < deferredArrayQueue.size() ; list_idx++ )
{
DeferredWriteFrame next_frame = deferredArrayQueue.get(list_idx);
if ( remove || index < next_frame.write_pos + next_frame.length )
{
remove = true;
deferred_writes -= next_frame.length;
index -= next_frame.length;
deferredArrayQueue.remove(list_idx);
}
}
}

deferredArrayQueue.add( new DeferredWriteFrame( index, offset, length, value ));
index += length;
deferred_writes += length;

}
else
{
Expand Down Expand Up @@ -1964,7 +1983,7 @@ private boolean write_special_value(final java.io.Serializable value)
return true;
}

Integer index = (Integer)getValueMap().get (value);
Integer index = getValueMap().get (value);
if (index != null)
{
// value has already been written -- make an indirection
Expand All @@ -1980,7 +1999,7 @@ private boolean write_special_value(final java.io.Serializable value)
*/
private void write_repository_id(final String repository_id)
{
Integer _index = (Integer)getRepIdMap().get (repository_id);
Integer _index = getRepIdMap().get (repository_id);
if ( _index == null)
{
// a new repository id -- write it
Expand Down Expand Up @@ -2017,7 +2036,7 @@ private void write_codebase(final String codebase)
}
else
{
_index = (Integer)getCodebaseMap().get (codebase);
_index = getCodebaseMap().get (codebase);
}
if ( _index == null)
{
Expand Down Expand Up @@ -2269,7 +2288,7 @@ else if (value instanceof org.omg.CORBA.portable.CustomValue )
if (newValue != value)
{
// look at the new value
Integer index = (Integer)getValueMap().get(newValue);
Integer index = getValueMap().get(newValue);
if (index != null)
{
// previously marshaled value -- make an indirection
Expand Down
44 changes: 44 additions & 0 deletions test/regression/idl/bug941.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module org
{
module jacorb
{
module test
{
module bugs
{
module bug941
{
struct Data
{
sequence <octet> bits;
};

interface MyServer
{
void setData (in Data few_bits);

void setBigData (in Data too_many_bits);

typedef fixed <5,2> fixedT;

readonly attribute short height; // height of the grid
readonly attribute short width; // width of the grid

// set the element [n,m] of the grid, to value:
void set(in short n, in short m, in fixedT value);

// return element [n,m] of the grid:
fixedT get(in short n, in short m);

exception MyException
{
string why;
};

short opWithException() raises( MyException );
};
};
};
};
};
};
85 changes: 85 additions & 0 deletions test/regression/src/org/jacorb/test/bugs/bug941/Bug941Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.jacorb.test.bugs.bug941;

/*
* JacORB - a free Java ORB
*
* Copyright (C) 1997-2013 Gerald Brose / The JacORB Team.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

import java.util.Arrays;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.jacorb.test.common.ClientServerSetup;
import org.jacorb.test.common.ClientServerTestCase;
import org.jacorb.test.common.TestUtils;

public class Bug941Test extends ClientServerTestCase
{
private org.omg.CORBA.Object server;

public Bug941Test(String name, ClientServerSetup setup)
{
super(name, setup);
}

public static Test suite()
{
Properties severProp = new Properties();

Properties clientProp = new Properties();
clientProp.setProperty("org.omg.PortableInterceptor.ORBInitializerClass.a",
MyInitializer.class.getName());

TestSuite suite = new TestSuite(Bug941Test.class.getName());

ClientServerSetup setup = new ClientServerSetup(suite,
"org.jacorb.test.bugs.bug941.TestObjectImpl",
clientProp, severProp);
TestUtils.addToSuite(suite, setup, Bug941Test.class);

return setup;
}

protected void setUp() throws Exception
{
server = setup.getServerObject();
}

protected void tearDown() throws Exception
{
server = null;
}

public void testBug941Test()
{
MyServer grid;

grid = MyServerHelper.narrow(server);

System.out.println ("### In main" );
byte [] petite_bite = new byte [1];
petite_bite[0] = 1;
Data tiny = new Data(petite_bite);
grid.setData(tiny);

byte [] grosse_bite = new byte [10000];
Arrays.fill(grosse_bite, (byte) 1);
Data biger = new Data(grosse_bite);
grid.setBigData(biger);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package org.jacorb.test.bugs.bug941;

/*
* JacORB - a free Java ORB
*
* Copyright (C) 1997-2013 Gerald Brose / The JacORB Team.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

import org.jacorb.orb.giop.RequestOutputStream;
import org.jacorb.orb.portableInterceptor.ClientRequestInfoImpl;
import org.omg.PortableInterceptor.ClientRequestInfo;
import org.omg.PortableInterceptor.ClientRequestInterceptor;
import org.omg.PortableInterceptor.ForwardRequest;

/**
* @author Nick Cross
*/

public class ClientInterceptor extends org.omg.CORBA.LocalObject implements ClientRequestInterceptor
{
public ClientInterceptor()
{
}

public String name()
{
return "ClientInterceptor941";
}

public void destroy()
{
}

public void send_request( ClientRequestInfo ri )
throws ForwardRequest
{
final RequestOutputStream output = ((ClientRequestInfoImpl) ri).getRequestStream ();

if (output != null && output.getBodyBegin() > 0)
{
int debut = output.getBodyBegin();
final int fin = output.size();
int resteALire = fin - debut;

if (resteALire > 0)
{
final byte[] buf = output.getBufferCopy();
final int pos = output.get_pos();

// skip header
output.skip(debut - pos);
// rewrite remaining
output.write_octet_array(buf, debut, resteALire);
}
}
}

public void send_poll(ClientRequestInfo ri)
{
}

public void receive_reply(ClientRequestInfo ri)
{
}

public void receive_exception(ClientRequestInfo ri)
throws ForwardRequest
{
}

public void receive_other(ClientRequestInfo ri)
throws ForwardRequest
{
}
}

0 comments on commit 8430901

Please sign in to comment.