aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/metadata
diff options
context:
space:
mode:
authorMartin Stockhammer <martin.stockhammer@ars.de>2017-10-21 14:42:32 +0200
committerMartin Stockhammer <martin.stockhammer@ars.de>2017-10-21 14:42:32 +0200
commitcb38dbbbc6f50f8a7a12adaf0afc42fe2c089599 (patch)
treed0fc0cc3b27a6fb233b89eb1cf0e6d8c25b113a3 /archiva-modules/metadata
parent2c12980a3a0a893375f89cd1ac60b8051483a377 (diff)
downloadarchiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.tar.gz
archiva-cb38dbbbc6f50f8a7a12adaf0afc42fe2c089599.zip
Changing the initialization behaviour of metadata repo factory
Diffstat (limited to 'archiva-modules/metadata')
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java53
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java4
-rw-r--r--archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java3
3 files changed, 60 insertions, 0 deletions
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java
new file mode 100644
index 000000000..66241cfd6
--- /dev/null
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/AbstractRepositorySessionFactory.java
@@ -0,0 +1,53 @@
+package org.apache.archiva.metadata.repository;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Implements just the open/close methods in a concurrent safe manner.
+ */
+public abstract class AbstractRepositorySessionFactory implements RepositorySessionFactory {
+
+ AtomicBoolean open = new AtomicBoolean();
+
+ protected abstract void initialize();
+
+ protected abstract void shutdown();
+
+ @Override
+ public void open() {
+ if (open.compareAndSet(false,true)) {
+ initialize();
+ }
+ }
+
+ @Override
+ public boolean isOpen() {
+ return open.get();
+ }
+
+ @Override
+ public void close() {
+ if(open.compareAndSet(true,false)) {
+ shutdown();
+ }
+ }
+}
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
index ba2c585d8..929c3c1a5 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactory.java
@@ -21,6 +21,10 @@ package org.apache.archiva.metadata.repository;
public interface RepositorySessionFactory
{
+ public void open();
+
+ public boolean isOpen();
+
RepositorySession createSession();
void close();
diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
index 3312a3cfb..6b398fd2a 100644
--- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
+++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/RepositorySessionFactoryBean.java
@@ -68,6 +68,9 @@ public class RepositorySessionFactoryBean
logger.info( "create RepositorySessionFactory with id {} instance of {}", //
id, //
repositorySessionFactory.getClass().getName() );
+ if (!repositorySessionFactory.isOpen()) {
+ repositorySessionFactory.open();
+ }
return repositorySessionFactory;
}