I am new on JBossCache. Reading the user documentation it says that a listener could be added to the Eviction class used, but I wasn't able to found how to do add one to the configuration file, or how that should be added.
I have tried to add an #CacheListener with a method #NodeEvicted, but that method
#CacheListener
public class EvictionListener {
#NodeEvicted
public void nodeEvicted(NodeEvent ne) {
System.out.println("Se borro el nodo");
}
}
and add it to the cache instance
CacheFactory factory = new DefaultCacheFactory();
this.cache = factory.createCache();
EvictionListener listener = new EvictionListener();
this.cache.create();
this.cache.addCacheListener(listener);
but the sysout isn't executed. For testing it, I am just running a simple Main value.
This is the configuration value I am using:
<jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:jboss:jbosscache-core:config:3.2">
<transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup"/>
<eviction wakeUpInterval="20">
<default algorithmClass="org.jboss.cache.eviction.FIFOAlgorithm" wakeUpInterval="20">
<property name="maxNodes" value="20" />
</default>
</eviction>
</jbosscache>
The problem was solved because I wasn't reading the XML configuration file.
I was missing:
factory.createCache(file);
Related
We are trying to integrate AWS S3 in our Kentico 10 application.
I followed this link:
https://docs.xperience.io/k10/custom-development/working-with-physical-files-using-the-api/configuring-file-system-providers/configuring-amazon-s3#ConfiguringAmazonS3-Medialibrarynotes
I created following module in App_Code => CMSModules => AWSS3 => AWSS3Module.cs
Here is the code of AWSS3Module.cs
using CMS;
using CMS.DataEngine;
using CMS.EventLog;
using CMS.IO;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
/*
Make sure following entries exists in web.config => <appSettings>
<add key="CMSAmazonBucketName" value="" />
<add key="CMSAmazonAccessKeyID" value="" />
<add key="CMSAmazonAccessKey" value="" />
<add key="CMSAmazonPublicAccess" value="true" />
<add key="CMSAmazonEndPoint" value="" />
*/
[assembly: RegisterModule(typeof(AWSS3Module))]
/// <summary>
/// Summary description for AWSS3Module
/// </summary>
public class AWSS3Module: Module
{
public AWSS3Module(): base("AWSS3Module")
{
//
// TODO: Add constructor logic here
//
}
// Initializes the module. Called when the application starts.
protected override void OnInit()
{
base.OnInit();
// Assigns a handler to the Insert.After event for OfficeInfo objects
EventLogProvider.LogInformation("AWSS3 module", "OnInit", "This code is running");
// Creates a new StorageProvider instance
AbstractStorageProvider mediaProvider = new StorageProvider("Amazon", "CMS.AmazonStorage");
// Specifies the target bucket
mediaProvider.CustomRootPath = ConfigurationManager.AppSettings["CMSAmazonBucketName"];
// Makes the bucket publicly accessible
mediaProvider.PublicExternalFolderObject = true;
// Maps a directory to the provider
StorageHelper.MapStoragePath("~/Sitename/", mediaProvider);
}
}
I read in one of the post that only new files will be synced. I tried adding few files in the media folder but nothing added in bucket.
There are no errors in logs. Also, I can see the module is loaded in the logs.
Bucket policy seems to be correct or I couldn't find issues in logs.
What am I doing wrong?
Also, if a file is uploaded, how can I get the S3 URL for that file?
Check this section:
StorageHelper.MapStoragePath("~/Sitename/", mediaProvider);
Make sure "/Sitename/" is the actual folder the media lib uses!
All you do here is basically instruct Kentico that there is an "alternative" way of storing files in folder 'x'. If your media lib is not storing in that exact folder it doesn't do anything.
I want to intercept a method call before execution using spring.NET. Let's assume the class/method to be intercepted is:
public class Listener
{
public void Handle()
{
// method body
}
}
This is what I've done (assuming all code is in a namespace called Example):
1.Created the advice:
public class MyAopAdvice : IMethodBeforeAdvice
{
public void Before(MethodInfo method, object[] args, object target)
{
// Advice action
}
}
2.Updated my spring xml configs:
<object id="myAopAdvice" type="Example.MyAopAdvice" />
<object id="listener" type="Spring.Aop.Framework.ProxyFactoryObject">
<property name="Target">
<object type="Example.Listener" autowire="autodetect"/>
</property>
<property name="InterceptorNames">
<list>
<value>myAopAdvice</value>
</list>
</property>
</object>
For some reason my Advice code is not getting hit if I put a breakpoint in it. However, if I add some console logging statements within my advice, it seems they are logged, but not at the appropriate time (i.e., before calling Listener.Handle()).
I'm willing to bet my configs are wrong (for once, I may be missing a way to tell the configs to listen for just the Handle method call and not any other method that Listener may have). Any ideas what's wrong?
Declare your Handle method as virtual:
public virtual void Handle() // ...
Your class does not implement any interfaces, which spring.net's default aop mechanism uses to create proxies. When spring.net does not find any interfaces to proxy, it looks for virtual methods to create a proxy for a class.
I have a simple java class which displays "waiting" text on execution , in "TMSCore" java project.
package com.stock.bo;
public class example {
/**
* #param args
*/
public static void main(String[] args) {
// ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
System.out.println("================================> waiting");
}
}
I have created TMSCore.jar and have set this example.class as entry point ,of my jar file.
Then i have created a module for this project in C:\Jboss\jboss-as-7.1.1\modules\org\tms\main , and pasted the jar in the same path
then i have created module.xml and pasted in the same path
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.tms">
<resources>
<resource-root path="TMSCore.jar"/>
</resources>
</module>
then i have created a jboss-deployment-structure.xml in my webproject/web-inf directory
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.tms"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
when i start the server with my war containing above jboss-deployment-structure.xml, in my console its showing deployed TMSCore.jar
but my "waiting" text in my jar is not displayed on console
my requirement is i should get "================================> waiting" on my console once jboss is started up
or else can any one can suggest how to make a jar to execute on starting jboss server?
BTW i am using JBOSS7.1
If I am right it's because JBoss doesn't execute a library, it only loads the classes contained in the jar file. So putting a main function and generating an executable jar will not help.
If your goal is to have an global module on the server, I suggest you these modifications:
Create the module (as you have already done)
Declare it as dependency in jboss-deployment-structure.xml (as you have already done)
Declare it as global module on the server, so it will be loaded only once by JBoss. Edit the configuration file standalone.xml and modify the section:
<subsystem xmlns="urn:jboss:domain:ee:1.0">
<global-modules>
<module name="org.tms" />
</global-modules>
</subsystem>
Now you have a module that have classes loaded only once. I you need to have only one instance of your Example class, the I suggest you to use an singleton:
public class Example {
// The only one instance
private static Example instance;
// Private constructor to avoid creation of other instances of this class
private Example()
{
System.out.println("================================> waiting");
}
public static Example getInstance()
{
if(instance == null)
{
instance = new Example();
}
return instance;
}
}
Then to use it in all projects on the server
Example ex = Example.getInstance();
will give you back the existing instance (or create one the first time).
Notice: I can't try, so no guarantee that that will work.
Edit: Maybe a small modification of the Example class can also make it run during the classes loading:
public class Example {
// The only one instance
private static Example instance = new Example();
// Private constructor to avoid creation of other instances of this class
private Example()
{
System.out.println("================================> waiting");
}
public static Example getInstance()
{
return instance;
}
}
Again: not tested.
You can't run a jar, but you can execute a startup method in a singleton.
#Startup
#Singleton
public class FooBean {
#PostConstruct
void atStartup() { ... }
#PreDestroy
void atShutdown() { ... }
}
This will happen at application start up and shutdown. I'd call the function you need from there.
See http://docs.oracle.com/javaee/6/tutorial/doc/gipvi.html
I'm using Apache-CXF for JAX-RS implementation. I have two resources which are defined in two bean. My jaxrs-server in context.xml os as follow
<jaxrs:server id="serverId" address="/">
<jaxrs:serviceBeans>
<bean id="bean1" class="com.Bean1" />
<bean id="bean2" class="com.Bean2" />
</jaxrs:serviceBeans>
</jaxrs:server>
Interface for Bean1 is as follows -
#Path("/")
public interface IBean1 {
#GET
#Path("/beaninfo1")
#Produces({ MediaType.APPLICATION_XML })
public Response checkBean1();
}
Interface for Bean2 is as follows -
#Path("/")
public interface IBean2 {
#GET
#Path("/beaninfo2")
#Produces({ MediaType.APPLICATION_XML })
public Response checkBean1();
}
I'm unable to hit the resource which is defined in last in serviceBans definition. In this case i'm able to hit Bean2 but not Bean1, getting 404 error, where as if i put Bean2 first and then Bean1, i'm able to hit Bean1 only.
Is there anything wrong with my configuration ?
It is possible to have the same #Path annotation at class level. You need to use a resourcecomparator. Please check this question
Yes. Give them different #Path annotations at the class level.
I am attempting to use S#arp Lite. I have followed the instructions here - https://github.com/codai/Sharp-Lite/blob/master/README.txt
When I first attempt to run the MappingIntegrationTests in NUnit, I receive the following errors:
MySolution.Tests.NHibernateProvider.MappingIntegrationTests.CanConfirmDatabaseMatchesMappings:
SetUp : NHibernate.HibernateException : Could not find named connection string MySolutionConnectionString
MySolution.Tests.NHibernateProvider.MappingIntegrationTests.CanConfirmDatabaseMatchesMappings:
SetUp : NHibernate.HibernateException : Could not find named connection string MySolutionConnectionString
NUnit indicates that the above errors are coming from the second line of the SetUp method in MappingIntegrationTests.
[SetUp]
public virtual void SetUp() {
_configuration = NHibernateInitializer.Initialize();
_sessionFactory = _configuration.BuildSessionFactory();
}
The Initialize method of my NHibernateInitializer class,
public static Configuration Initialize() {
Configuration configuration = new Configuration();
configuration.Proxy(p => p.ProxyFactoryFactory<DefaultProxyFactoryFactory>())
.DataBaseIntegration(db => {
db.ConnectionStringName = "MySolutionConnectionString";
db.Dialect<MsSql2008Dialect>();
})
.AddAssembly(typeof(ActionConfirmation<>).Assembly)
.CurrentSessionContext<LazySessionContext>();
ConventionModelMapper mapper = new ConventionModelMapper();
mapper.WithConventions(configuration);
return configuration;
}
And the App.Config file from MySolution.Tests project,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MySolutionConnectionString" connectionString="data source=.\SQLEXPRESS;Initial Catalog=MySolutionDB-DEV;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</ connectionStrings>
</configuration>
I don't understand why the NUnit test runner is failing with the message Could not find named connection string MySolutionConnectionString. According to James Kovacs' blog post on Loquacious Configuration, this seems like this should work no problem -
"Setting db.ConnectionStringName causes NHibernate to read the connection string from the config section of the [App|Web].config."
MySolution.Tests is a dll but App.configs are only read for the starting .exe file which is the NUnit testrunner.