Any refreshable groovy classloader implement? - groovy

I am looking for a refreshable groovy classloader,I want to let groovy file change on fly,I know
GroovyScriptEngine do the thing,but if I have AClass.groovy and BClass.groovy, and I write in AClass:
Class pageClass = ClassUtils.forName("BClass", this.getClass().getClassLoader());
and auto reloading BClass is not work when BClass.groovy is not work.
I think the best solution is need a refreshable ClassLoader,but I can not find the exisiting implemention.
And I am not using spring-groovy and grails,I want a independent implemention.
Thanks

Not exactly what you want I'm sure but if you want to do something ONLY with Groovy (no Spring or Grails) that allows you to change stuff and not have to restart your application, you might look at doing some initial work with Groovlets -> http://groovy.codehaus.org/Groovlets
This is only for servlet container work and probably won't be extremely useful as your application gets large but it would allow you to initially change things frequently and simply refresh with a call to the Groovlet.
If you did consider using Spring, scripted beans are 'refreshable' and you can implement that yourself using Java's dynamic language support but I'd suggest simply letting Spring do it for you.

Related

How to change the Apache POI SXSSFWorkbook default temporary file name

I am using POI's SXSSFWorkbench class to create extremely large workbooks. Multiple processes may be running of my application concurrently, so I thought it prudent to append the processId to the default temporary filename. I don't know how to do that, and could not find any recent coding examples.
Can anyone point me to an example, or outline to me what has to be done? I see there is a static TempFile.createTempFile method. Should I be executing that using a class override before instantiating the SXSSFWorkbook class? Or after?
I also saw there was a DefaultTempFileCreationStrategy class. Could not find examples of how to use this either.
The main class that Apache POI uses for this is TempFile
The method you'll want to call is TempFile.setTempFileCreationStrategy
What you'll need to do is create your own class implementing the interface TempFileCreationStrategy. This is nice and simple, with just two methods, createTempDirectory and createTempFile.
To get an idea of what's involved, you can look at the source code for DefaultTempFileCreationStrategy online here. It's pretty easy, just put in the logic for your own needs in terms of threading and naming.

Customizing a jdbcChannelMessageStore in Spring Integration

I'm relatively new with SI (I say "relatively" because I did some work with SI version 0.6 to 1, but I had to stop then and I'm now on it again in 4.2.5) and for now I'm writing some prototypes for POCs. In one of then I configured a channel backed by a jdbcChannelMessageStore which I wanted to customize in a simple way. To change the column MESSAGE_BYTES from bytea to text.
So I changed the schema-postgresql.sql to include that change and hope that I could only rewrite the jdbc statement for the INSERT. However, even if the statement itself is easily changeable, setting the parameters is not, since it is buried inside a lambda inside the jdbcTemplate.update itself inside the addMessageToGroup method. So the only solution would be to override the entire addMessageToGroup method, which seems not a good solution at all, since it contains more logic than the simple jdbc insert.
So what ended up doing was what I commented on my code as // very big hack. I overriden the DefaultLobHandler to actually not use the lob at all but a setString(...) instead.
So, I have a question and a suggestion:
Is there a way customize the JdbcChannelMessageStore to have our own schema structure and/or our own statements, without using things like this "big hack"?
If there is no better way, can I suggest to at least put the prepared statement fields setters on it's own protected (or public) method, instead of a lambda inside the jdbcUpdate?
Thanks in advance.
We should probably make it easier to override that logic, perhaps by delegating to an overridable method.
Contributions are always welcome :).

How to display timeline information for routines used by controllers in glimpse/Asp.NET MVC

I am currently using Asp.Net MVC 4 and I would like to include the time of some routines used by my controllers in the glimpse's timeline tab.
I know that I have to create an ITimeLineMessage Implementation and send the timing information with a message broker. But how to create the ITimeLineMessage ?
Here is an implementation using anthonyv's suggestion:
https://gist.github.com/droyad/8292852
Here is a way but its not very nice and not supported:
Retrieve the MessageBroker for the following static method:
Glimpse.Core.Framework.GlimpseConfiguration.GetConfiguredMessageBroker()
Then publish an ITimelineMessage to the MessageBroker:
messageBroker.Publish(timelineMessage)
Note, you could create a generic message type that you use over again that implements ITimelineMessage
To populate the properties of your ITimelineMessage implementation you might also need IExecutionTimer. You can get this via the following static method:
Glimpse.Core.Framework.GlimpseConfiguration.GetConfiguredTimerStrategy()
The above will have the knowledge of when the request started for offsets etc.
As #nikmd23 said, we know this is about as bad as what you could ever want to do but v2 will see a much much more simple way of doing this.
You can create any custom class you want, that class just has to implement ITimelineMessage.
As a general heads up, we are currently working through a way to make this WAY easier. If the approach described there interests you, please do provide your feedback.

Webappclass loader unable to load superclass in a hook?

I am using liferay ce 6.1.0.I need to extend LayoutAction class in a hook.But the class cannot be loaded in the hook by the class loader
Caused by: java.lang.NoClassDefFoundError: com/liferay/portal/action/LayoutAction
java.lang.ClassNotFoundException: com.liferay.portal.action.LayoutAction
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
Is this the issue with the class loader or am I supposed use a different subclass of the following in order to extends.
Thanks in advance
I want to override includeLayoutContent() method of LayoutAction class in order to have a track on the number of views of a page.If this class cannot be extended,is there any other means or class which can be extended to achieve the same
com.liferay.portal.action.LayoutAction is in portal-impl.jar, which is not available to hooks. Therefor you cannot do this.
If you would give us a hint what you want to achieve with this, somebody might be able to tell you how to do what you want to do.
With your added information I'll give you a hint: Typically, a write operation for every pageview is considered to be quite expensive: Your portal's performance will suffer from this. I'd rather advise to use external tools like google anayltics, piwik or similar ones to generate statistics, including the pageviews for specific pages.
Another method, if you can live with the lower potential performance, is to embed such a method in your theme - the theme gets access to the current page and can execute additional functionality with this. Preferably you'll position this at the end of the page, when everything else has already been rendered and sent to the client.

can I use XmlSlurper directly on a w3c.dom.Node object

I am experimenting with GroovyWS in the hope of completely replacing Axis2 client code.
One of the Webservice operations I call returns fragments of XML, which I need to turn into Groovy Beans.
I am getting instances of com.sun.org.apache.xerces.internal.dom.ElementNSImpl coming out of the WebService call.
I can call new XmlSlurper().parseText(it as String) where it is the instance of ElementNSImpl.
However, of course this writes the Element out to a String before reparsing and slurping it. Is there a way to avoid this unnecessary step ?
Ultimately I want to turn the slurped object into a Groovy Bean; is there a better way to do this. I was wondering about DomToGroovy, but this still gives me a string that I then have run in a Groovy Shell.
I don't think XmlSlurper supports direct conversions like that, you'd probably have to write something yourself. Maybe if you dig in to the XmlSlurper source there will be a way to do it by extending and adding a new parse() method. Otherwise, unless you have major performance concerns, I'd say you're on the right track.

Resources