Skip to content

Commit

Permalink
ftp: Add LoginCellProvider for FTP
Browse files Browse the repository at this point in the history
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
gbehrmann committed Dec 9, 2013
1 parent 641a644 commit 97c8ac6
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 19 deletions.
Expand Up @@ -15,7 +15,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import dmg.cells.nucleus.CDC;
import dmg.cells.nucleus.CellCommandListener;
Expand All @@ -27,7 +26,6 @@
import dmg.util.StreamEngine;

import org.dcache.cells.AbstractCell;
import org.dcache.cells.Option;
import org.dcache.util.FireAndForgetTask;
import org.dcache.util.Transfer;

Expand All @@ -45,17 +43,14 @@ public class LineBasedDoor
{
private static final Logger LOGGER = LoggerFactory.getLogger(LineBasedDoor.class);

@Option(name = "interpreter",
description = "Protocol interpreter",
required = true)
protected Class<LineBasedInterpreter> interpreterClass;
private final Class<? extends LineBasedInterpreter> interpreterClass;

/**
* Door instances are created by the LoginManager. This is the
* stream engine passed to us from the LoginManager upon
* instantiation.
*/
private StreamEngine engine;
private final StreamEngine engine;

private LineBasedInterpreter interpreter;

Expand All @@ -64,22 +59,21 @@ public class LineBasedDoor

/**
* Shared executor for processing commands.
*
* FIXME: This will be created within the thread group creating
* the first door. This will usually be the login manager and
* works fine, but it isn't clean.
*/
private static final ExecutorService EXECUTOR =
Executors.newCachedThreadPool();
private final ExecutorService executor;

private Thread workerThread;

public LineBasedDoor(String name, StreamEngine engine, Args args)
public LineBasedDoor(String cellName, Args args, Class<? extends LineBasedInterpreter> interpreterClass,
StreamEngine engine, ExecutorService executor)
{
super(name, args);
super(cellName, args);

this.interpreterClass = interpreterClass;
this.engine = engine;
this.executor = executor;

try {
this.engine = engine;
doInit();
workerThread.start();
} catch (InterruptedException e) {
Expand Down Expand Up @@ -285,7 +279,7 @@ public synchronized void add(String command)
if (!isRunning) {
final CDC cdc = new CDC();
isRunning = true;
EXECUTOR.submit(new FireAndForgetTask(new Runnable()
executor.submit(new FireAndForgetTask(new Runnable()
{
@Override
public void run()
Expand Down
@@ -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();
}
}
@@ -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();
}
}
@@ -0,0 +1 @@
diskCacheV111.doors.LineBasedDoorProvider
3 changes: 1 addition & 2 deletions skel/share/services/ftp.batch
Expand Up @@ -49,8 +49,7 @@ check ftp.mover.queue
exec file:${dcache.paths.share}/cells/stage.fragment ftp doors

create dmg.cells.services.login.LoginManager ${ftp.cell.name} \
"${ftp.net.port} diskCacheV111.doors.LineBasedDoor \
-interpreter=${ftp.implementation} \
"${ftp.net.port} ${ftp.implementation} \
-listen=${ftp.net.listen} \
-prot=raw \
-export=${ftp.cell.export} \
Expand Down

0 comments on commit 97c8ac6

Please sign in to comment.