Commit fdc56bad authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

src: add Spring integration module

Motivation:
To use NFSServerV41 with spring a constructor argument injection is
required. This makes spring configuration more complicated, as some
arguments are optional and **null** values have to be injected.

Modification:
Add NfsServerFactory, which implements Spring's FactoryBean and enables
simpler integration, for instance where device manager must null:

```
    <bean id="nfs-v41" class="org.dcache.nfs.v4.NFSServerV41Factory">
        <description>NFSv4.1 MDS server</description>
        <property name="operationFactory" ref="mds-factory"/>
        <property name="vfs" ref="vfs"/>
        <property name="exportFile" ref="export"/>
     </bean>
```

instead of:

```
    <bean id="nfs-v41" class="org.dcache.nfs.v4.NFSServerV41">
        <description>NFSv4.1 MDS server</description>
        <constructor-arg ref="mds-factory"/>
        <constructor-arg index="1"><null/></constructor-arg>
        <constructor-arg ref="vfs" />
        <constructor-arg ref="export"/>
     </bean>
```

Result:
Simpler integration with Spring.

Acked-by: Paul Millar
Target: master
parent 74ed1559
......@@ -38,6 +38,7 @@
<modules>
<module>core</module>
<module>basic-client</module>
<module>spring</module>
</modules>
<build>
......@@ -124,6 +125,11 @@
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.dcache</groupId>
<artifactId>oncrpc4j-core</artifactId>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dcache</groupId>
<artifactId>nfs4j</artifactId>
<version>0.16.0-SNAPSHOT</version>
</parent>
<name>Spring integarion for nfs4j</name>
<groupId>org.dcache</groupId>
<artifactId>nfs4j-spring</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.dcache</groupId>
<artifactId>nfs4j-core</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* Copyright (c) 2017 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program (see the file COPYING.LIB for more
* details); if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.dcache.nfs.v4;
import org.dcache.nfs.ExportFile;
import org.dcache.nfs.v4.nlm.LockManager;
import org.dcache.nfs.vfs.VirtualFileSystem;
import org.springframework.beans.factory.FactoryBean;
/**
* A helper class to simplify Spring and NFS4J integration.
*/
public class NFSServerV41Factory implements FactoryBean<NFSServerV41> {
private final NFSServerV41.Builder builder = new NFSServerV41.Builder();
@Override
public NFSServerV41 getObject() throws Exception {
return builder.build();
}
@Override
public Class<?> getObjectType() {
return NFSServerV41.class;
}
@Override
public boolean isSingleton() {
return false;
}
public void setDeviceManager(NFSv41DeviceManager deviceManager) {
builder.withDeviceManager(deviceManager);
}
public void setOperationFactory(NFSv4OperationFactory operationFactory) {
builder.withOperationFactory(operationFactory);
}
public void setVfs(VirtualFileSystem vfs) {
builder.withVfs(vfs);
}
public void setLockManager(LockManager nlm) {
builder.withLockManager(nlm);
}
public void setExportFile(ExportFile exportFile) {
builder.withExportFile(exportFile);
}
public void setStateHandler(NFSv4StateHandler stateHandler) {
builder.withStateHandler(stateHandler);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment