How to start my cron job on startup of alfresco server? - cron

How can I start my scheduler on startup of Alfresco server?
Liferay provide onstartup server event. Is there any similar kind of functionality available in the Alfresco where can I start my Cron job on start of Alfresco server?

It does not make sense to use cron or a similar service if you want to run custom code at startup time. Add your custom Spring managed bean derived from org.springframework.extensions.surf.util.AbstractLifecycleBean to a file tomcat/shared/classes/alfresco/extension/startup-context.xml (or equivalent). Put your code in the onBootstrap method.

Another good way to to this is to extend the AbstractModuleComponent implementing the method executeInternal and in the Spring configuration set the executeOnlyOnce to false.
In this way your custom code will be executed every time Alfresco starts.
Below an example of a Spring configuration:
<bean id="initJobsComponent" class="com.sourcesense.alfresco.component.InitJobsComponent" parent="module.baseComponent" >
<property name="moduleId" value="myModuleId" />
<property name="name" value="initComponent" />
<property name="description" value="You description" />
<property name="sinceVersion" value="1.0" />
<property name="appliesFromVersion" value="1.0" />
<property name="executeOnceOnly" value="false"/>
</bean>
Your Java class must extend AbstractModuleComponent:
public class InitJobsComponent extends AbstractModuleComponent {
...
#Override
protected void executeInternal() throws Throwable {
//put here your custom code
}
...
}
Hope this helps.

To fit your need you could launch execution of your job by appending it to alfresco launch script.
Edit :
/etc/init.d/alfresco
Put into "start" section your job, example:
case $1 in
start)
sh YOUR_CRON_JOB
[....]
;;

Related

Performance Issue using DefaultMessageListenerContainer with CachingConnectionFactory

In our application we are using SingleConnectionFactory with DefaultMessageListenerContainer consuming from IBM MQ server, performance wise the app is doing pretty good, however on MQ end our application is opening too many new connections randomly. Here is the current config we have.
Try with this instead of caching or single:
<bean id="connectionFactory" class="org.springframework.jms.connection.DelegatingConnectionFactory">
<property name="targetConnectionFactory" ref="primaryRawInputConnectionFactory" />
<property name="shouldStopConnections" value="true"/>
</bean>

how to export spring task:executor as mbean?

We are using task:executor in our spring integration application. We need to monitor this threadpool via mbean browser. So far we have good control over all spring integration channels , message handlers etc and those are showing in our mbean browser but we like to see task executor threadpool also be visible so we can see how many threads are in pool, how many being used etc
Is it possible to export them as mbean? if so how it can be done?
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="exec:name=exec" value-ref="exec" />
</map>
</property>
</bean>
<task:executor id="exec" />

Hybris HAC Update Scenario

I wrote an interceptor in one of my projects to intercept all the requests. So usually in a spring project i will do normal build and start the server and my changes related to an interceptor will start reflecting. However this doesn't seem to be the case with a hybris project.
Do I need to do update in hybris hac as well? And if I do then out of the available below mentioned options which options do i need to choose and why.
1. Update running system
2. Clear the hMC configuration from the database
3. Create essential data
4. Localize types
Thanks,
Ashish
To answer the second part of your question, I have listed at least one reason for selecting each type of options. Hope this helps.
Update running system - Required when hybris type definition changes. For example, changing the content of file <extnesion-name>-items.xml
Clear the hMC configuration from the database - If you have chosen to persist hmc configuration in the Database and changing it. For example, changing content in the file hmc.xml
Create essential data - If there is a change in the content in the impex files which follows the naming pattern of essentialdata*.impex.
Localize types - If there is a change in the properties files for localizations. for example changing the content in file <extension-name>-locales_en.properties
Assuming you've not made any changes to any underlying data objects (Jalo items) then you won't need to run an update in the hybris hAC.
You should just be able to make your changes, run ant clean all from the platform and then start up the hybris ECP instance and your changes will be visible.
If this is a normal Spring MVC interceptor, then it should work fine.
Have you checked your spring configuration in the storefront extension you are working from?
For example, take a look at the accelerator Spring MVC configuration file:
hybris/bin/ext-template/yacceleratorstorefront/web/webroot/WEB-INF/config/spring-mvc-config.xml
This has some examples where this is used out-of-the-box:
<mvc:interceptors>
<ref bean="beforeControllerHandlerInterceptor" />
<ref bean="beforeViewHandlerInterceptor" />
<ref bean="csrfHandlerInterceptor" />
</mvc:interceptors>
As an example, the default before controller handler interceptor is defined as:
<!-- Interceptor that runs once per request and before the controller handler method is called -->
<alias name="defaultBeforeControllerHandlerInterceptor" alias="beforeControllerHandlerInterceptor" />
<bean id="defaultBeforeControllerHandlerInterceptor" class="de.hybris.platform.yacceleratorstorefront.interceptors.BeforeControllerHandlerInterceptor" >
<property name="beforeControllerHandlers">
<ref bean="beforeControllerHandlersList" />
</property>
</bean>
which references:
<alias name="defaultBeforeControllerHandlersList" alias="beforeControllerHandlersList" />
<util:list id="defaultBeforeControllerHandlersList" >
<!-- List of handlers to run -->
<bean class="de.hybris.platform.yacceleratorstorefront.interceptors.beforecontroller.SecurityUserCheckBeforeControllerHandler" />
<bean class="de.hybris.platform.yacceleratorstorefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler" >
<property name="userService" ref="userService"/>
<property name="redirectStrategy" ref="redirectStrategy"/>
...
</bean>
<bean class="de.hybris.platform.yacceleratorstorefront.interceptors.beforecontroller.DeviceDetectionBeforeControllerHandler" />
...
</util:list>
So you could either override this using the alias with your own implementation, or add additional controller handlers to the list.
As there is no change to the underlying data model - this is just wiring up Spring MVC related classes - no need for an update system or anything like that. Just an 'ant clean all' to recompile to pick up your new interceptor classes, and server restart to pick up the change in the Spring cornfiguraton.

how to add a retry advice with jms:message-driven-channel-adapter

I am new to spring integration. My requirement is that if there is a connection problem to the jms q then it should try to connect 3 times then log it and exit the process. I am not able to do it. It throws an error saying it needs the ref attribute for service:activator. But I don't have/know reference of which class to provide here. Is there any other way of doing it?
<int-jms:message-driven-channel-adapter id="msgIn" channel="toRoute" container="messageListenerContainer" />
<int:service-activator id="service" input-channel="toRoute" >
<int:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
<property name="recoveryCallback">
<bean class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
<constructor-arg ref=“errorChannel" />
</bean>
</property>
</bean>
</request-handler-advice-chain>
</int:service-activator>
You seem to have completely misunderstood what the framework does.
The service-activator gets a message when one is received from JMS (which implies the connection is good), and needs "something" (a reference to a bean or an expression) to invoke as a result of receiving that message.
The retry advice is to retry calling that service if it fails to process the message for some reason. It is unrelated to whatever is the source of the message (JMS in this case).
It's not clear why you are trying to use Spring Integration for something as simple as testing whether a JMS broker is available.
Perhaps if you can provide some larger context someone might be able to help.

FTP/FTPS Adapters custom trigger/poller

First, I have just started looking at Spring Integration today, so I have very little experience. I already have a basic scheduled ftp file parser setup using spring integration:
<int:channel id="ftpIn" />
<int-ftp:inbound-channel-adapter
channel="ftpIn"
session-factory="ftpClientFactory"
filename-pattern="*.xml"
local-directory="${TEMP_DIR}">
<int:poller fixed-rate="${ftp.polling.rate}" />
</int-ftp:inbound-channel-adapter>
<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${ftp.host}" />
<property name="port" value="${ftp.port}" />
<property name="username" value="${ftp.username}" />
<property name="password" value="${ftp.password}" />
</bean>
<int:service-activator
input-channel="ftpIn"
method="handle"
ref="ftpInHandler" />
<bean id="ftpInHandler" class="thanks.for.looking.FtpInHandler" />
This works; however, I want to add additional functionality that checks (at a fixed-rate) if the system is ready before starting the scheduled (fixed-rate) ftp adapter. I am stuck on the best way to implement this. Any help or guidance is appreciated.
Best Regards,
Jared
<poller> has an option like <advice-chain>.
So you just need to write some custom Advice:
public class CheckSystemInterceptor implements MethodInterceptor {
Object invoke(MethodInvocation invocation) throws Throwable {
return mySystem.isOK() ? invocation.proceed() : null;
}
}
Configure it as a <bean> with your system checker and inject it into that <advice-chain>.
It will be invoked on each poll.

Resources