Search in sources :

Example 1 with Session

use of org.neo4j.shell.Session in project neo4j by neo4j.

the class BashVariableInterpreterTest method customInterpreter.

@Test
public void customInterpreter() throws Exception {
    // GIVEN
    interpreter.addReplacer("test", new Replacer() {

        @Override
        public String getReplacement(ShellServer server, Session session) throws ShellException {
            return "Hello";
        }
    });
    // WHEN
    String interpreted = interpreter.interpret("\\test world", server, session);
    // THEN
    assertEquals("Hello world", interpreted);
}
Also used : ShellServer(org.neo4j.shell.ShellServer) Replacer(org.neo4j.shell.impl.BashVariableInterpreter.Replacer) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session) Test(org.junit.Test)

Example 2 with Session

use of org.neo4j.shell.Session in project neo4j by neo4j.

the class SimpleAppServer method welcome.

@Override
public Welcome welcome(Map<String, Serializable> initialSession) throws RemoteException, ShellException {
    Serializable clientId = newClientId();
    if (clientSessions.containsKey(clientId)) {
        throw new IllegalStateException("Client " + clientId + " already initialized");
    }
    Session session = newSession(clientId, initialSession);
    clientSessions.put(clientId, session);
    try {
        String message = noWelcome(initialSession) ? "" : getWelcomeMessage();
        return new Welcome(message, clientId, getPrompt(session));
    } catch (ShellException e) {
        throw new RemoteException(e.getMessage());
    }
}
Also used : Serializable(java.io.Serializable) Welcome(org.neo4j.shell.Welcome) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Example 3 with Session

use of org.neo4j.shell.Session in project neo4j by neo4j.

the class SimpleAppServer method newSession.

private Session newSession(Serializable id, Map<String, Serializable> initialSession) throws ShellException {
    Session session = new Session(id);
    initialPopulateSession(session);
    for (Map.Entry<String, Serializable> entry : initialSession.entrySet()) {
        session.set(entry.getKey(), entry.getValue());
    }
    return session;
}
Also used : Serializable(java.io.Serializable) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Session(org.neo4j.shell.Session)

Example 4 with Session

use of org.neo4j.shell.Session in project neo4j by neo4j.

the class AbstractAppServer method interpretLine.

@Override
public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
    Session session = getClientSession(clientId);
    if (line == null || line.trim().length() == 0) {
        return new Response(getPrompt(session), Continuation.INPUT_COMPLETE);
    }
    try {
        Continuation commandResult = null;
        for (String command : line.split(Pattern.quote("&&"))) {
            command = TextUtil.removeSpaces(command);
            command = replaceAlias(command, session);
            AppCommandParser parser = new AppCommandParser(this, command);
            commandResult = parser.app().execute(parser, session, out);
        }
        return new Response(getPrompt(session), commandResult);
    } catch (Exception e) {
        throw wrapException(e);
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Aggregations

Session (org.neo4j.shell.Session)4 ShellException (org.neo4j.shell.ShellException)3 Serializable (java.io.Serializable)2 RemoteException (java.rmi.RemoteException)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.Test)1 AppCommandParser (org.neo4j.shell.AppCommandParser)1 Continuation (org.neo4j.shell.Continuation)1 Response (org.neo4j.shell.Response)1 ShellServer (org.neo4j.shell.ShellServer)1 Welcome (org.neo4j.shell.Welcome)1 Replacer (org.neo4j.shell.impl.BashVariableInterpreter.Replacer)1