Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a dedicating FTP provider for LoginCellFactory allows the shared executor to be bound to the lifetime of the LoginManager. Target: trunk Require-notes: no Require-book: no Acked-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de> Patch: http://rb.dcache.org/r/6310/
- Loading branch information
Showing
5 changed files
with
103 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
modules/dcache-ftp/src/main/java/diskCacheV111/doors/LineBasedDoorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package diskCacheV111.doors; | ||
|
||
import com.google.common.util.concurrent.AbstractService; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import dmg.cells.nucleus.Cell; | ||
import dmg.cells.services.login.LoginCellFactory; | ||
import dmg.util.Args; | ||
import dmg.util.StreamEngine; | ||
|
||
import static diskCacheV111.doors.LineBasedDoor.LineBasedInterpreter; | ||
|
||
public class LineBasedDoorFactory extends AbstractService implements LoginCellFactory | ||
{ | ||
private final Class<? extends LineBasedInterpreter> interpreter; | ||
private final String cellName; | ||
private final Args args; | ||
private ExecutorService executor; | ||
|
||
public LineBasedDoorFactory(Class<? extends LineBasedInterpreter> interpreter, Args args, String parentCellName) | ||
{ | ||
this.interpreter = interpreter; | ||
this.cellName = parentCellName + "*"; | ||
this.args = args; | ||
} | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return interpreter.getSimpleName(); | ||
} | ||
|
||
@Override | ||
public Cell newCell(StreamEngine engine, String userName) throws InvocationTargetException | ||
{ | ||
return new LineBasedDoor(cellName, args, interpreter, engine, executor); | ||
} | ||
|
||
@Override | ||
protected void doStart() | ||
{ | ||
this.executor = Executors.newCachedThreadPool(); | ||
notifyStarted(); | ||
} | ||
|
||
@Override | ||
protected void doStop() | ||
{ | ||
executor.shutdown(); | ||
notifyStopped(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
modules/dcache-ftp/src/main/java/diskCacheV111/doors/LineBasedDoorProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package diskCacheV111.doors; | ||
|
||
import dmg.cells.services.login.LoginCellFactory; | ||
import dmg.cells.services.login.LoginCellProvider; | ||
import dmg.util.Args; | ||
|
||
import static diskCacheV111.doors.LineBasedDoor.LineBasedInterpreter; | ||
|
||
public class LineBasedDoorProvider implements LoginCellProvider | ||
{ | ||
@Override | ||
public int getPriority(String name) | ||
{ | ||
try { | ||
if (LineBasedInterpreter.class.isAssignableFrom(Class.forName(name))) { | ||
return 100; | ||
} | ||
} catch (ClassNotFoundException ignored) { | ||
} | ||
return Integer.MIN_VALUE; | ||
} | ||
|
||
@Override | ||
public LoginCellFactory createFactory(String name, Args args, String parentCellName) throws IllegalArgumentException | ||
{ | ||
try { | ||
Class<?> interpreter = Class.forName(name); | ||
if (LineBasedInterpreter.class.isAssignableFrom(interpreter)) { | ||
return new LineBasedDoorFactory(interpreter.asSubclass(LineBasedInterpreter.class), args, parentCellName); | ||
} | ||
} catch (ClassNotFoundException ignored) { | ||
} | ||
throw new IllegalArgumentException(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...cache-ftp/src/main/resources/META-INF/services/dmg.cells.services.login.LoginCellProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
diskCacheV111.doors.LineBasedDoorProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters