Search Results

Search found 595 results on 24 pages for 'groovy'.

Page 6/24 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • groovy thread for urls

    - by Srinath
    I wrote logic for testing urls using threads. This works good for less number of urls and failing with more than 400 urls to check . class URL extends Thread{ def valid def url URL( url ) { this.url = url } void run() { try { def connection = url.toURL().openConnection() connection.setConnectTimeout(10000) if(connection.responseCode == 200 ){ valid = Boolean.TRUE }else{ valid = Boolean.FALSE } } catch ( Exception e ) { valid = Boolean.FALSE } } } def threads = []; urls.each { ur - def reader = new URL(ur) reader.start() threads.add(reader); } while (threads.size() 0) { for(int i =0; i < threads.size();i++) { def tr = threads.get(i); if (!tr.isAlive()) { if(tr.valid == true){ threads.remove(i); i--; }else{ threads.remove(i); i--; } } } Could any one please tell me how to optimize the logic and where i was going wrong . thanks in advance.

    Read the article

  • code formatter for grails and Groovy?

    - by Jared
    I'm currently using a basic text editor to write my grails code. Does anyone know of a program that will automatically format code with indentation similar to indent does for C? I'd rather use a commandline program to do this but can use an IDE to format my code if that's the only option.

    Read the article

  • groovy closure parameters

    - by Don
    Hi, The following example of using the sendMail method provided by the grails mail plugin appears in this book. sendMail { to "[email protected]" subject "Registration Complete" body view:"/foo/bar", model:[user:new User()] } I understand that the code within {} is a closure that is passed to sendMail as a parameter. I also understand that to, subject and body are method calls. I'm trying to figure out what the code that implements the sendMail method would look like, and my best guess is something like this: MailService { String subject String recipient String view def model sendMail(closure) { closure.call() // Code to send the mail now that all the // various properties have been set } to(recipient) { this.recipient = recipient } subject(subject) { this.subject = subject; } body(view, model) { this.view = view this.model = model } } Is this reasonable, or am I missing something? In particular, are the methods invokedwithin the closure (to, subject, body), necessarily members of the same class as sendMail? Thanks, Don

    Read the article

  • Best way to code this, string to map conversion in Groovy

    - by Daxon
    I have a string like def data = "session=234567893egshdjchasd&userId=12345673456&timeOut=1800000" I want to convert it to a map ["session", 234567893egshdjchasd] ["userId", 12345673456] ["timeout", 1800000] This is the current way I am doing it, def map = [:] data.splitEachLine("&"){ it.each{ x -> def object = x.split("=") map.put(object[0], object[1]) } } It works, but is there a more efficient way?

    Read the article

  • Import text file crunching library for Java/Groovy ?

    - by devdude
    In a lot of real life implementations of applications we face the requirement to import some kind of (text) files. Usually we would implement some (hardcoded?) logic to validate the file (eg. proper header, proper number of delimiters, proper date/time value,etc.). Eventually also need to check for the existence of related data in a table (eg. value of field 1 in text file must have an entry in some basic data table). While XML solves this (to some extend) with XSD and DTD, we end up hacking this again and again for proprietary text file formats. Is there any library or framework that allows the creation of templates similar to the xsd approach ? This would make it way more flexible to react on file format changes or implement new formats. Thanks for any hints Sven

    Read the article

  • splat operator in groovy?

    - by IttayD
    def foo(map, name) { println(map) } foo("bar", hi: "bye") will print [hi:bye] Now I have a previous map that I wish to pass along to foo. In pseudo code, something like: def otherMap = [hi: "world"] foo("bar", hi: "bye", otherMap*) So that it prints [hi:world] This doesn't work of course. Also, trying to pass just the map mixes the order of arguments: def otherMap = [hi: "world"] foo("bar", otherMap) will print bar How can I fix this?

    Read the article

  • Groovy & Grails Concurrency ( quartz, executor )

    - by Pietro
    What I'm trying to do is to run multiple threads at some starting time. Those threads must stay alive for 90minutes after start. During the 90minutes they execute something after a random sleep time (ex: 5minutes to 15minutes). Here is a pseudo code on how I would implement it. The problem is that doing it in this way the threads run in an unexpected way. How can I implement correctly something like this? Class MyJob { static triggers = { cron name: 'first', cronExpression: "0 30 21 * * FRI" cron name: 'second', cronExpression: "0 30 19 * * FRI" cron name: 'third', cronExpression: "0 30 17 * * FRI" def myService def execute() { switch( between trigger name ) case 'first': model = Model.findByAttribute(...) ... myService.run( model, start_time ) break; ... } } class MyService { def run( model, start_time ) { def end_time = end_time.plusMinutes(90) model.fields.each( field -> Thread.start { executeSomeTasks( field, start_time, end_time ) } ) } def executeSomeTasks( field, start_time, end_time ) { while( start_time < end_time ) { ...do something ... sleep( Random.nextInt( 1000 ) ); } } }

    Read the article

  • Groovy htmlunit getFirstByXPath returning null

    - by StartingGroovy
    I have had a few issues with HtmlUnit returning nulls lately and am looking for guidance. each of my results for grabbing the first row of a website have returned null. I am wondering if someone can A) explain why they might be returning null B) explain better ways (if there are some) to go about getting the information Here is my current code (URL is in the source): client = new WebClient(BrowserVersion.FIREFOX_3) client.javaScriptEnabled = false def url = "http://www.hidemyass.com/proxy-list/" page = client.getPage(url) IpAddress = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[2]").getValue() println "IP Address is: $data" //returns null //Port_Number is an Image Country = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[4][@class='country']/@rel").getValue() println "Country abbreviation is: $Country" //differentiate speed and connection by name of gif? Type = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[7]").getValue() println "Proxy type is: $Type" Anonymity = page.getFirstByXPath("//html/body/div/div/form/table/tbody/tr/td[8]").getValue() println "Anonymity Level is: $Anonymity" client.closeAllWindows() Right now all of my XPaths return null and .getValue() obviously doesn't work on null. I also have questions as to what I should do about the PORT since it is an image? Is there a better alternative than downloading it and attempting to solve it by OCR? Side Note There is no significance in this site, I was just looking for a site that I could practice scraping on (the last one I ran into issues of fragment identities and couldn't get an answer to: HtmlUnit getByXpath returns null and HtmlUnit and Fragment Identities )

    Read the article

  • Create comma separated string from 2 lists the groovy way

    - by Micor
    What I have so far is: def imageColumns = ["products_image", "procuts_subimage1", "products_subimage2", "prodcuts_subimage3", "products_subimage4"] def imageValues = ["1.jpg","2.jpg","3.jpg"] def imageColumnsValues = [] // only care for columns with values imageValues.eachWithIndex { image,i -> imageColumnsValues << "${imageColumns[i]} = '${image}'" } println imageColumnValuePair.join(", ") It works but I think it could be better. Wish there was a collectWithIndex ... Any suggestions?

    Read the article

  • How to use Groovy Set for unique elements?

    - by Guy
    As simple as this must be I still can't understand where am I wrong: class A { boolean equals(o) { true } } def s = [new A(), new A()] as Set assert s.size() == 1 // Assertion failed: actually gives 2 Which method should I override in order to get uniqueness?

    Read the article

  • Best IDE for Grails/Groovy?

    - by fernandogarcez
    I am starting a project with Grails since I already use Eclipse, it was my first choice. But I don´t think its good enough, had some problems and the plugging is poor in functionalities. Anyone uses/tested others IDEs(NetBeans, InteliJ(not free)...)? Which one is the best? thanks.

    Read the article

  • creating proxy object in groovy

    - by IttayD
    Hi, I am looking for how to write a method that accepts some value and returns a proxy to that value where the underlying value can be retrieved with an accessor: def p = toProxy(1) assert p == 1 assert p * 2 == 2 assert p.underlying == 1 def p2 = toProxy(objWithMethodFoo) p2.foo() p2.underlying.foo() I want to do this per object instance (not for all objects of some class) and without the need to use special 'use' constructs.

    Read the article

  • How to make System command calls in Java/Groovy?

    - by Zombies
    What I want to do is invoke maven from a groovy script. The groovy script in question is used as a maven wrapper to build J2EE projects by downloading a tag and invoking maven on what was downloaded. How should I accomplish invoking maven to build/package the EAR (the groovy script is already capable of downloading the tag from SCM).

    Read the article

  • Why don't my groovy enums work, or even compile?

    - by ?????
    I'm running Groovy Version: 1.7.0 JVM: 1.6.0_17 (Update -- I just upgraded to 1.7.1 and get the same errors!) I've tried to use enums, using the exact syntax from the groovy documentation, and each time I see the compile error: Groovy:The class java.lang.Enum refers to the class java.lang.Enum and uses 1 parameters, but the referred class takes no parameters Any ideas on what's going on? For example: This code won't compile or run, and gets the error above. enum VehicleStatus { OFF, IDLING, ACCELERATING, DECELARATING } class Vehicle { Long id Long version VehicleStatus status }

    Read the article

  • Make methods that do not depend on instance fields, static?

    - by m3th0dman
    Recently I started programming in Groovy for a integration testing framework, for a Java project. I use Intellij IDEA with Groovy plug-in and I am surprised to see as a warning for all the methods that are non-static and do not depend on any instance fields. In Java, however, this is not an issue (at least from IDE's point of view). Should all methods that do not depend onto any instance fields be transformed into static functions? If true, is this specific to Groovy or it is available for OOP in general? And why?

    Read the article

  • Jacob + Microsoft SpeechAPI trouble

    - by guai
    Following groovy code kills JVM on SetInterest method invocation It uses Scriptom, the groovy DSL for Jacob Spend whole day searching SAPI's SPFEI macro to rewrite it in groovy. Don't sure does it came out right. Or maybe other bugs %) Help welcomed import org.codehaus.groovy.scriptom.* import static org.codehaus.groovy.scriptom.tlb.sapi.SpeechVoiceSpeakFlags.* import static org.codehaus.groovy.scriptom.tlb.sapi.SpeechRunState.* import static org.codehaus.groovy.scriptom.tlb.sapi.SpeechLib.* import static org.codehaus.groovy.scriptom.tlb.sapi.SPEVENTENUM.* def spfei(Integer[] args) { res = 1<<SPEI_RESERVED1 | 1<<SPEI_RESERVED2 args.each {res |= 1<<it} res } Scriptom.inApartment { def voice = new ActiveXObject('SAPI.SpVoice') evtsrc = voice.toInterface(ISpEventSource) evtsrc.setInterest(spfei(SPEI_WORD_BOUNDARY), spfei(SPEI_WORD_BOUNDARY)) evtsrc.events.Callbacks = {args -> println 'jjj'} voice.speak "Hello, world", SVSFlagsAsync }

    Read the article

  • HTTP Builder/Groovy - get source text _and_ XmlSlurper output?

    - by Misha Koshelev
    Dear All: I am reading here: http://groovy.codehaus.org/modules/http-builder/doc/get.html I seem to be able to get i) XMLSlurper output as parsed by NekoHTML using: def http = new HTTPBuilder('http://www.google.com') def html = http.get( path : '/search', query : [q:'Groovy'] ) ii) Raw text using: http.get( path : '/search', contentType : TEXT, query : [q:'Groovy'] ) { resp, reader -> println "response status: ${resp.statusLine}" println 'Headers: -----------' resp.headers.each { h -> println " ${h.name} : ${h.value}" } println 'Response data: -----' System.out << reader println '\n--------------------' } I am having some trouble and would like to get BOTH (i) and (ii) to debug my XmlSlurper code on the actual html I am getting. Any suggestions how I might go about doing this? I can easily instantiate an XmlSlurper object with the relevant string using the parseString(string) method or the parse(reader) method, but I cannot seem to get the Neko processing step correct. Any hints? Thank you! Misha

    Read the article

  • Is it possible to replace groovy method for existing object?

    - by Jean Barmash
    The following code tried to replace an existing method in a Groovy class: class A { void abc() { println "original" } } x= new A() x.abc() A.metaClass.abc={-> println "new" } x.abc() A.metaClass.methods.findAll{it.name=="abc"}.each { println "Method $it"} new A().abc() And it results in the following output: original original Method org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod@103074e[name: abc params: [] returns: class java.lang.Object owner: class A] Method public void A.abc() new Does this mean that when modify the metaclass by setting it to closure, it doesn't really replace it but just adds another method it can call, thus resulting in metaclass having two methods? Is it possible to truly replace the method so the second line of output prints "new"? When trying to figure it out, I found that DelegatingMetaClass might help - is that the most Groovy way to do this?

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >