Friday, 15 March 2013

java - Java8 dynamic proxy and default methods -



java - Java8 dynamic proxy and default methods -

having dynamic proxy interface default methods, how invoke default method? using defaultmethod.invoke(this, ...) proxy invocation handler called (which somehow correct, cause have no implementing class interface).

i have workaround using asm create class implementing interface , delegating such calls instance of class. not solution, if default method calls other interface methods (you delegator ping-pong). jls surprisingly silent question...

here little code example:

class="lang-java prettyprint-override">public class java8proxy implements invocationhandler { public interface withdefaultmethod { void somemethod(); default void somedefaultmethod() { system.out.println("default method invoked!"); } } @test public void invoketest() { withdefaultmethod proxy = (withdefaultmethod) proxy.newproxyinstance( withdefaultmethod.class.getclassloader(), new class<?>[] { withdefaultmethod.class }, this); proxy.somedefaultmethod(); } @override public object invoke(object proxy, method method, object[] args) throws throwable { // assuming not knowing interface before runtime (i wouldn't utilize // proxy, i?) // here line printed out? // loop // method.invoke(this, args); homecoming null; } }

you can utilize methodhandles type in invocationhandler.

if (method.isdefault()) { homecoming methodhandles.lookup() .in(method.getdeclaringclass()) .unreflectspecial(method, method.getdeclaringclass()) .bindto(proxy) .invokewitharguments(args); }

java java-8

dbunit - gradle test doesn't work well -



dbunit - gradle test doesn't work well -

when run test in intellij, works well, if run command line like

gradle test or gradle clean test

it rerurns java.io.filenotfoundexception

string file_path = "sample/src/test/resources/" idataset insertdataset = new flatxmldataset(new fileinputstream(file_path + "com/sample/mst.xml"));

project construction is:

testproject

sample src main test java com sample test.java resources com sample mst.xml wrong, should do?

you should alter file loading code to:

getclass().getclassloader().getresourceasstream("mst.xml")

gradle dbunit

sql - why does LIMIT 2 take orders of magnitude longer than LIMIT 1 in this query? -



sql - why does LIMIT 2 take orders of magnitude longer than LIMIT 1 in this query? -

i'm on postgresql 9.3. should reproduce on table 100,000+ rows. explain analyze shows many more rows getting scanned limit 2, can't figure out why.

limit 1:

explain analyze base of operations ( select *, row_number() on () rownum a_big_table ), filter ( select rownum, true thing base of operations ) select * base of operations left bring together filter using (rownum) filter.thing limit 1

result:

limit (cost=283512.19..283517.66 rows=1 width=2114) (actual time=0.019..0.019 rows=1 loops=1) cte base of operations -> windowagg (cost=0.00..188702.69 rows=4740475 width=101) (actual time=0.008..0.008 rows=1 loops=1) -> seq scan on a_big_table (cost=0.00..129446.75 rows=4740475 width=101) (actual time=0.003..0.003 rows=1 loops=1) cte filter -> cte scan on base of operations base_1 (cost=0.00..94809.50 rows=4740475 width=8) (actual time=0.000..0.000 rows=1 loops=1) -> nested loop (cost=0.00..307677626611.24 rows=56180269915 width=2114) (actual time=0.018..0.018 rows=1 loops=1) bring together filter: (base.rownum = filter.rownum) -> cte scan on base of operations (cost=0.00..94809.50 rows=4740475 width=2113) (actual time=0.011..0.011 rows=1 loops=1) -> cte scan on filter (cost=0.00..94809.50 rows=2370238 width=9) (actual time=0.002..0.002 rows=1 loops=1) filter: thing total runtime: 0.057 ms

limit 2:

explain analyze base of operations ( select *, row_number() on () rownum a_big_table ), filter ( select rownum, true thing base of operations ) select * base of operations left bring together filter using (rownum) filter.thing limit 2

result:

limit (cost=283512.19..283523.14 rows=2 width=2114) (actual time=0.018..14162.283 rows=2 loops=1) cte base of operations -> windowagg (cost=0.00..188702.69 rows=4740475 width=101) (actual time=0.008..4443.359 rows=4714243 loops=1) -> seq scan on a_big_table (cost=0.00..129446.75 rows=4740475 width=101) (actual time=0.002..1421.622 rows=4714243 loops=1) cte filter -> cte scan on base of operations base_1 (cost=0.00..94809.50 rows=4740475 width=8) (actual time=0.001..10214.684 rows=4714243 loops=1) -> nested loop (cost=0.00..307677626611.24 rows=56180269915 width=2114) (actual time=0.018..14162.280 rows=2 loops=1) bring together filter: (base.rownum = filter.rownum) rows removed bring together filter: 4714243 -> cte scan on base of operations (cost=0.00..94809.50 rows=4740475 width=2113) (actual time=0.011..0.028 rows=2 loops=1) -> cte scan on filter (cost=0.00..94809.50 rows=2370238 width=9) (actual time=0.009..6595.770 rows=2357122 loops=2) filter: thing total runtime: 14247.374 ms

engine first runs, limits. so, can see much more rows.

sql postgresql join common-table-expression window-functions

c# - Setting per request value for ServicePointManager.SecurityProtocol -



c# - Setting per request value for ServicePointManager.SecurityProtocol -

this question has reply here:

set securityprotocol (ssl3 or tls) on .net httpwebrequest per request 4 answers

in c# able set static value ssl3 or tls, e.g.

servicepointmanager.securityprotocol = securityprotocoltype.tls;

or:

servicepointmanager.securityprotocol = securityprotocoltype.ssl3;

but (i believe) impact future httpwebrequest objects in application.

is there way set given httpwebrequest or @ to the lowest degree given uri?

note have seen this:

uri uri = new uri(url); servicepoint sp = servicepointmanager.findservicepoint(uri);

but servicepoint not have securityprotocol property.

at nowadays thinking have set static global property prior creating new httpwebrequest.

this doesn't sense right , means:

i have create sure multiple threads not doing @ same time. i not sure point setting has been 'used' (i.e. when phone call webrequest.getresponse() servicepointmanager.securityprotocol accessed , bound uri?).

realised has been covered here:

how utilize ssl3 instead of tls in particular httpwebrequest?

and here:

set securityprotocol (ssl3 or tls) on .net httpwebrequest per request

confirming fears. users appear spinning separate app domain work around this. still think might possible thread locking if defined @ point setting bound particular web request object.

c# ssl httpwebrequest

Replying on the same thread in a mailing list using git send-email -



Replying on the same thread in a mailing list using git send-email -

i had submitted patch organisation's mailing list , need send revised version of patch on same thread using git send-email. have set chainreplyto value false. had tried earlier:

git send-email --no-chain-reply-to --to="mailing-list@organisation.org" --in-reply-to="[org-devel] [patch] added functionality" added-functionality.patch

this creating new thread instead of replying existing one. right way of replying?

refer tutorial. might reply http://burzalodowa.wordpress.com/2013/10/05/how-to-send-patches-with-git-send-email/

git email mailing-list

sockets - Runing class method multiple times parallel in Python -



sockets - Runing class method multiple times parallel in Python -

i have implemented python socket server. sends image info multiple cameras client. request handler class looks like:

class requesthandler(socketserver.baserequesthandler): def handle(self): while true: info = self.request.recv(1024) if data.endswith('0000000050'): # client requests info camera_id, camera_path in _video_devices.iteritems(): message = self.create_image_transfer_message(camera_id, camera_path) self.request.sendto(message, self.client_address) def create_image_transfer_message(self, camera_id, camera_path): # somecode ...

i forced stick socket server because of client. works problem works sequentially, there big delays between photographic camera images beingness uploaded. create transfer messages in parallel little delay between calls.

i tried utilize pool class multiprocessing:

import multiprocessing class requesthandler(socketserver.baserequesthandler): def handle(self): ... pool = multiprocessing.pool(processes=4) messages = [pool.apply(self.create_image_transfer_message, args=(camera_id, camera_path)) camid, campath in _video_devices.iteritems()]

but throws:

picklingerror: can't pickle <type 'function'>: attribute lookup __builtin__.function failed

i want know if there way create transfer messages in parallel defined delay between calls?

edit:

i create response messages using info multiple cameras. problem is, if run image grabbing routines close each other image artifacts, because usb bus overloaded. figured out, calling image grabbing sequentially 0.2 sec delay solve problem. cameras not sending info whole time image grabbing function running, delayed parallel cal result in images little delay between them.

i think you're on right path already, no need throw away work.

here's reply how utilize class method multiprocessing found via google after searching "multiprocessing class method"

from multiprocessing import pool import time pool = pool(processes=2) def unwrap_self_f(arg, **kwarg): homecoming c.create_image_transfer_message(*arg, **kwarg) class requesthandler(socketserver.baserequesthandler): @classmethod def create_image_transfer_message(cls, camera_id, camera_path): # logic goes here def handle(self): while true: info = self.request.recv(1024) if not data.endswith('0000000050'): # client requests info go on pool.map(unwrap_self_f, ( (camera_id, camera_path) camera_id, camera_path in _video_devices.iteritems() ) )

note, if want homecoming values workers you'll need explore using shared resource see reply here - how can recover homecoming value of function passed multiprocessing.process?

python sockets multiprocessing socketserver

How to change image permission with PHP and chmod? -



How to change image permission with PHP and chmod? -

as want display uploaded images on website message: "you don't have permission access /funproject/uploads/328/20.jpg on server".

i had problem before , solved using chmod somehow deleted solution , can't create now.

i got function that:

function upload_image($image_temp, $image_ext, $album_id) { $album_id = (int)$album_id; mysql_query("insert `images` values ('', '".$_session['user_id']."', '$album_id', unix_timestamp(), '$image_ext')"); $image_id = mysql_insert_id(); $image_file = $image_id.'.'.$image_ext; move_uploaded_file($image_temp, 'uploads/'.$album_id.'/'.$image_file); create_thumb('uploads/'.$album_id.'/', $image_file, 'uploads/thumbs/'.$album_id.'/'); }

what have tried (and doesn't work):

mysql_query("insert `images` values ('', '".$_session['user_id']."', '$album_id', unix_timestamp(), '$image_ext')"); chmod($image_file, 0755);

how can alter permission of uploaded image using chmod in function?

that worked!

mysql_query("insert `images` values ('', '".$_session['user_id']."', '$album_id', unix_timestamp(), '$image_ext')"); chmod("/somedir/uploads", 775);

php chmod