OverlappingFileLockException when starting tomcat

I added a custom jndi-resource factory to my tomcat (jndi-resource for ConnectionFactory inline hornetq). My resource needs some configuration files; I put them in a folder ${catalina_home}/hornetq. I have a test web application that uses this resource when starting tomcat. When tomcat starts, when the test-web application wants to use my resource, the resource wants to lock the configuration files, but it cannot, and it throws an "OverlappingFileLockException:

java.nio.channels.OverlappingFileLockException
    at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
    at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:1056)
    at org.hornetq.core.server.impl.FileLockNodeManager.tryLock(FileLockNodeManager.java:266)
    at org.hornetq.core.server.impl.FileLockNodeManager.isBackupLive(FileLockNodeManager.java:82)
    at org.hornetq.core.server.impl.HornetQServerImpl$SharedStoreLiveActivation.run(HornetQServerImpl.java:2161)
    at org.hornetq.core.server.impl.HornetQServerImpl.start(HornetQServerImpl.java:450)
    at org.hornetq.jms.server.impl.JMSServerManagerImpl.start(JMSServerManagerImpl.java:485)
    at org.hornetq.jms.server.embedded.EmbeddedJMS.start(EmbeddedJMS.java:115)
    at ...

Is it possible to disable file locking (files in a directory ${catalina_home}/hornetq) in tomcat or OS?

Update:

My jndi resource in a file context.xmlin tomcat (factory connection with the name: /ConnectionFactorydefined in hornetq-jms.xml):

<Resource name="jms/ConnectionFactory" auth="Container" 
    type="javax.jms.ConnectionFactory"
    factory="com.wise.jms.hornetq.embedded.HornetqConnectionFactoryBuilder"
    cf-name="/ConnectionFactory" singletone="true"/>

factory : HornetqConnectionFactoryBuilder. jar, ${catalina_home}/lib ( hornetq getObjectInstance):

public class HornetqConnectionFactoryBuilder implements ObjectFactory{

    private EmbeddedJMS embeddedJMS;
    private static final String ConnectionFactoryName = "cf-name";
    private static final String HornetqConfigDirectoryPath = getCatalinaHomePath() + "/conf/hornetq/";
    private static final String JmsConfigFilePath = HornetqConfigDirectoryPath + "hornetq-jms.xml";
    private static final String HornetqConfigFilePath = HornetqConfigDirectoryPath + "hornetq-configuration.xml";

    @Override
    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception{
        Properties properties = initProperties((Reference) obj);
        validateProperties(properties);
        initHornetq();
        String connectionFactoryJndiName = (String) properties.get(ConnectionFactoryName);
        return embeddedJMS.lookup(connectionFactoryJndiName);
    }

    private synchronized void initHornetq() throws Exception{
        if (embeddedJMS == null){
            embeddedJMS = new EmbeddedJMS();
            embeddedJMS.setJmsConfigResourcePath(JmsConfigFilePath);
            embeddedJMS.setConfigResourcePath(HornetqConfigFilePath);
            embeddedJMS.start();
        }
    }

    private Properties initProperties(Reference reference) throws IOException{
        Enumeration<RefAddr> addresses = reference.getAll();
        Properties properties = new Properties();
        while (addresses.hasMoreElements()) {
            RefAddr address = addresses.nextElement();
            String type = address.getType();
            String value = (String) address.getContent();
            properties.put(type, value);
        }
        return properties;
    }

    private void validateProperties(Properties properties){
        validateSingleProperty(properties, ConnectionFactoryName);
    }

    private static String getCatalinaHomePath(){
        String catalinaHome = System.getenv("CATALINA_HOME");
        if (catalinaHome == null){
            throw new IllegalArgumentException("CATALINA_HOME environment variable should be set");
        }
        return "file:///" + catalinaHome.replaceAll("\\\\", "/");
    }

    private static void validateSingleProperty(Properties properties, String propertyName){
        if (!properties.containsKey(propertyName)){
            throw new IllegalArgumentException(propertyName + " property should be set.");
        }
    }
}

- Test ( -):

public class Test{
    private ConnectionFactory connectionFactory;

    public Test() throws NamingException{
        Context initCtx = new InitialContext();
        Context envCtx = (Context) initCtx.lookup("java:comp/env");
        connectionFactory = (ConnectionFactory) envCtx.lookup("jms/ConnectionFactory");
    }

    public void test() throws JMSException{
        Connection connection = connectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(true,Session.SESSION_TRANSACTED);
        Queue queue = session.createQueue("testQueue");
        MessageProducer messageProducer = session.createProducer(queue);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        TextMessage message1 = session.createTextMessage("This is a text message1");
        messageProducer.send(message1);
        session.commit();
        TextMessage receivedMessage = (TextMessage) messageConsumer.receive(5000);
        session.commit();
        System.out.println("Message1 received after receive commit: " + receivedMessage.getText());
    }

    public void setConnectionFactory(ConnectionFactory connectionFactory){
        this.connectionFactory = connectionFactory;
    }
}

:, (hornetq) jar class-path, , ! (tomcat: 6, hornetq: 2.4.0.Final, : windows 7)

+4
1

Tomcat? , tomcat , lib.

tomcat webapps Tomcat.

0

Source: https://habr.com/ru/post/1539281/


All Articles