IOException from MemoryMappedBuffer 's force() method....

S

santanuc

Hi friends!

I am new to this group and am facing with a peculiar problem. I have
written a program that uses MemoryMappedBuffer.

CODE:
==================

public void save(long row, int column, long data) throws IOException
{
long size = LongBigArray.this.max_column * 8;
long channelStartp;
if(lbuffer == null)
{System.out.println("buffer null Curr row="+current_row+"
row="+row+" column="+column);
current_row = row;
channelStartp = current_row * LongBigArray.this.max_column * 8;
//size of long = 64 bits or 8 bytes
ByteBuffer bbuffer =
ByteBuffer.allocate((int)size);System.out.println("b4 wirte start
pointer="+channelStartp+" channel size="+fchannel.size());
while(bbuffer.position() < bbuffer.limit())
{
bbuffer.put((byte)LongBigArray.this.padChar);
}
fchannel.write(bbuffer,channelStartp);
//fchannel.force(true);
lbuffer =
fchannel.map(FileChannel.MapMode.READ_WRITE,channelStartp,size);
System.out.println("buffer null start pointer="+channelStartp+"
channel size="+fchannel.size());
}
else if(current_row != row)
{System.out.println("Curr row="+current_row+" row="+row+"
column="+column);
current_row = row;
channelStartp = current_row * LongBigArray.this.max_column * 8;
//size of long = 64 bits or 8 bytes
/*if(lbuffer.capacity() > 0)
{System.out.println("Buffer capacity = "+lbuffer.capacity()+"
channel size="+fchannel.size());
((MappedByteBuffer)lbuffer).force();
}*/
if(channelStartp >= fchannel.size())
{System.out.println("start pointer="+channelStartp+" channel
size="+fchannel.size());
ByteBuffer bbuffer = ByteBuffer.allocate((int)size);
while(bbuffer.position() < bbuffer.limit())
{
bbuffer.put((byte)LongBigArray.this.padChar);
}

fchannel.write(bbuffer,channelStartp);
//fchannel.force(true);
System.out.println("after force start
pointer="+channelStartp+" channel size="+fchannel.size());
}
lbuffer =
fchannel.map(FileChannel.MapMode.READ_WRITE,channelStartp,size);
}
System.out.println("after put Save called");
lbuffer.asLongBuffer().put(column,data);
((MappedByteBuffer)lbuffer).force();
}

Now when this code segment is run for consecutive values of
channelStartp there is no problem. But when the situation arise such
that channelStartp can have non-consecutive values, or more
particularly at the very start if it has a value > 0 then I am getting
an IOException and the stack trace shows that the exception was caused
by the native force0 which has been called from the force() method of
MemoryMappedBuffer.

below is the stack trace
=========================

Cannot generate shape objects: java.io.IOException
com.silicogene.affinity.qscd.util.QSCDDataAccessException:
java.io.IOException
at
com.silicogene.affinity.qscd.util.LongBigArray.put(LongBigArray.java:155)
at
com.silicogene.affinity.qscd.data.QSCDSurfaceSet.addSurface(QSCDSurfaceSet.java:80)
at
com.silicogene.affinity.qscd.geom.SurfaceGenerator.plane2Surfaces(SurfaceGenerator.java:132)
at
com.silicogene.affinity.qscd.geom.SurfaceGenerator.generateSurface(SurfaceGenerator.java:100)
at
com.silicogene.affinity.qscd.QSCDApplication.execute(QSCDApplication.java:271)
at
com.silicogene.affinity.qscd.QSCDApplication.main(QSCDApplication.java:339)
Caused by: java.io.IOException
at java.nio.MappedByteBuffer.force0(Native Method)
at java.nio.MappedByteBuffer.force(MappedByteBuffer.java:138)
at
com.silicogene.affinity.qscd.util.LongBigArray$BufferManager.save(LongBigArray.java:74)
at
com.silicogene.affinity.qscd.util.LongBigArray.put(LongBigArray.java:151)
.... 5 more

All tutorials and even the API document says that force() does not
throw any exception. I am bugged! can't understand the reason of the
exception. Can anyone here please help to find out the cause.

Santanu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top