Unix Technical Forum

Re: about monitoring the input stream

This is a discussion on Re: about monitoring the input stream within the pgsql Interfaces jdbc forums, part of the PostgreSQL category; --> Marc, > Why don't you decorate the InputStream with some simple > CountingInputStream of yours, just like Oliver suggested? ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Interfaces jdbc

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-16-2008, 12:17 AM
Albert Cardona
 
Posts: n/a
Default Re: about monitoring the input stream


Marc,

> Why don't you decorate the InputStream with some simple
> CountingInputStream of yours, just like Oliver suggested?


> Something very similar to:
> private java.io.DataOutputStream#incCount()


> If you are lazy you could even extend BufferInputStream; like this
> you have just two read methods to override.



The idea is not to modify the driver one bit in benefit of uncontroversial
deployment of my application (TrakEM2 at
http://www.ini.unizh.ch/~acardona/trackem2.html ). If java was lisp I would
simply alter the register to replace the InputStream, but it isn't and/or I
don't know how to use reflection to that extent (I don't know what would
happen was I to replace the InputStream using reflection once a connection
has been created).

Therefore I ask for suggestions on how to monitor the downloading rate ...
If there aren't any, well, tough luck! I'll have to live with it.

Albert




---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-16-2008, 12:17 AM
Mark Lewis
 
Posts: n/a
Default Re: about monitoring the input stream

If you're trying to add diagnostic data collection to all sockets you
could provide a custom SocketFactory implementation which returned
wrappers around Sockets that return CountingInputStream objects instead
of regular InputStream objects to the getInputStream() method.

I don't think that the PG JDBC driver allows you to specify a custom
socketFactory, but you could always set the default system socket
factory. If you do other network operations in the same JVM, your
factory could be smart enough to ignore sockets that don't connect to
your PG server/port.

-- Mark Lewis


On Wed, 2006-09-13 at 18:09 +0200, Albert Cardona wrote:
> Marc,
>
> > Why don't you decorate the InputStream with some simple
> > CountingInputStream of yours, just like Oliver suggested?

>
> > Something very similar to:
> > private java.io.DataOutputStream#incCount()

>
> > If you are lazy you could even extend BufferInputStream; like this
> > you have just two read methods to override.

>
>
> The idea is not to modify the driver one bit in benefit of uncontroversial
> deployment of my application (TrakEM2 at
> http://www.ini.unizh.ch/~acardona/trackem2.html ). If java was lisp I would
> simply alter the register to replace the InputStream, but it isn't and/or I
> don't know how to use reflection to that extent (I don't know what would
> happen was I to replace the InputStream using reflection once a connection
> has been created).
>
> Therefore I ask for suggestions on how to monitor the downloading rate ...
> If there aren't any, well, tough luck! I'll have to live with it.
>
> Albert
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings


---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 12:17 AM
Marc Herbert
 
Posts: n/a
Default Re: about monitoring the input stream

Albert Cardona <acardona@ini.phys.ethz.ch> writes:

> The idea is not to modify the driver one bit in benefit of uncontroversial
> deployment of my application (TrakEM2 at
> http://www.ini.unizh.ch/~acardona/trackem2.html ). If java was lisp I would
> simply alter the register to replace the InputStream, but it isn't and/or I
> don't know how to use reflection to that extent


Thanks to its reflection API, java is actually lisp. Just a bit less
convenient. This should do the trick:

pg_input_field = PGStream.class.getDeclaredField("pg_input");

pg_input_field.setAccessible(true);

InputStream orig_stream = (InputStream) pg_input_field.get(pg_stream_to_hack);

InputStream counting_stream = new CountingInputStream(orig_stream);

pg_input_field.set(pg_stream_to_hack, counting_stream);



> (I don't know what would happen was I to replace the InputStream
> using reflection once a connection has been created).


As far as I understand the driver you _have to_ replace it after the
connection has been created. Just avoid using it before replace.





---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:29 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com