@Override public void start() throws IOException { if (authToken != null) { try { // TODO should we receive an AuthException instead of an IOException? NetworkUtil.authToServer(reader, writer, authToken); } catch (IOException ioe) { shutdown(true); throw ioe; } } }
/** * <p> * Shuts down the connection by closing the socket, the writer, and the reader. * </p> * * <p> * Internal: at this point, the connection has not been given back to the connections deque, or the deque is about * to be cleared. * </p> */ @Override public void shutdown(boolean reset) { if (reset) { NetworkUtil.quietlySetLinger(socket); } // XXX Close socket first, otherwise, reader.close() will block if stuck on readLine. NetworkUtil.quietlyClose(socket); NetworkUtil.quietlyClose(reader); NetworkUtil.quietlyClose(writer); }
/** * * @param reader * @return A String of at least one character (space if null or empty). * @throws IOException */ public static String safeReadLine(BufferedReader reader) throws IOException { return safeReadLine(reader, true); }
NetworkUtil.quietlyClose(sSocket); ArrayList<Py4JServerConnection> tempConnections = new ArrayList<Py4JServerConnection>(connections); for (Py4JServerConnection connection : tempConnections) {
@Override public void shutdown(boolean reset) { if (reset) { NetworkUtil.quietlySetLinger(socket); } // XXX Close socket first, otherwise, reader.close() will block if stuck on readLine. NetworkUtil.quietlyClose(socket); NetworkUtil.quietlyClose(reader); NetworkUtil.quietlyClose(writer); socket = null; writer = null; reader = null; if (!initiatedFromClient) { // Only fires this event when the connection is created by the JavaServer to respect the protocol. fireConnectionStopped(); } }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String returnCommand = null; String subCommand = safeReadLine(reader); if (subCommand.equals(MEMORY_DEL_SUB_COMMAND_NAME)) { returnCommand = deleteObject(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown Memory SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
public void start() throws IOException { logger.info("Starting Communication Channel on " + address + " at " + port); socket = socketFactory.createSocket(address, port); socket.setSoTimeout(blockingReadTimeout); reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), Charset.forName("UTF-8"))); writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), Charset.forName("UTF-8"))); if (authToken != null) { try { // TODO should we receive an AuthException instead of an IOException? NetworkUtil.authToServer(reader, writer, authToken); } catch (IOException ioe) { shutdown(true); throw ioe; } } }
/** * <p> * Shuts down the connection by closing the socket, the writer, and the reader. * </p> * <p> * Internal: emits a connection stopped signal so GatewayServer can remove the connection from the connections list. * In rare occasions, the shutdown method may be called twice (when the server shuts down at the same time as the * connection fails and shuts down). * </p> */ @Override public void shutdown(boolean reset) { if (reset) { NetworkUtil.quietlySetLinger(socket); } // XXX Close socket first, otherwise, reader.close() will block if stuck on readLine. NetworkUtil.quietlyClose(socket); NetworkUtil.quietlyClose(reader); NetworkUtil.quietlyClose(writer); fireConnectionStopped(); } }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String returnCommand = null; String subCommand = safeReadLine(reader, false); if (subCommand.equals(HELP_OBJECT_SUB_COMMAND_NAME)) { returnCommand = getHelpObject(reader); } else if (subCommand.equals(HELP_CLASS_SUB_COMMAND_NAME)) { returnCommand = getHelpClass(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown Help SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == GET_UNKNOWN_SUB_COMMAND_NAME) { returnCommand = getUnknownMember(reader); } else if (subCommand == GET_JAVA_LANG_CLASS_SUB_COMMAND_NAME) { returnCommand = getJavaLangClass(reader); } else { returnCommand = getMember(reader); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String returnCommand = null; String subCommand = safeReadLine(reader, false); if (subCommand.equals(FIELD_GET_SUB_COMMAND_NAME)) { returnCommand = getField(reader); } else if (subCommand.equals(FIELD_SET_SUB_COMMAND_NAME)) { returnCommand = setField(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown Field SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == CREATE_VIEW_SUB_COMMAND_NAME) { returnCommand = createJVMView(reader); } else if (subCommand == IMPORT_SUB_COMMAND_NAME) { returnCommand = doImport(reader); } else if (subCommand == REMOVE_IMPORT_SUB_COMMAND_NAME) { returnCommand = removeImport(reader); } else if (subCommand == SEARCH_SUB_COMMAND_NAME) { returnCommand = search(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown JVM View SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == LIST_SLICE_SUB_COMMAND_NAME) { returnCommand = slice_list(reader); } else if (subCommand == LIST_CONCAT_SUB_COMMAND_NAME) { returnCommand = concat_list(reader); } else if (subCommand == LIST_MULT_SUB_COMMAND_NAME) { returnCommand = mult_list(reader); } else if (subCommand == LIST_IMULT_SUB_COMMAND_NAME) { returnCommand = imult_list(reader); } else if (subCommand == LIST_COUNT_SUB_COMMAND_NAME) { returnCommand = count_list(reader); } else { returnCommand = call_collections_method(reader, subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { char subCommand = safeReadLine(reader).charAt(0); String returnCommand = null; if (subCommand == ARRAY_GET_SUB_COMMAND_NAME) { returnCommand = getArray(reader); } else if (subCommand == ARRAY_SET_SUB_COMMAND_NAME) { returnCommand = setArray(reader); } else if (subCommand == ARRAY_SLICE_SUB_COMMAND_NAME) { returnCommand = sliceArray(reader); } else if (subCommand == ARRAY_LEN_SUB_COMMAND_NAME) { returnCommand = lenArray(reader); } else if (subCommand == ARRAY_CREATE_SUB_COMMAND_NAME) { returnCommand = createArray(reader); } else { returnCommand = Protocol.getOutputErrorCommand("Unknown Array SubCommand Name: " + subCommand); } logger.finest("Returning command: " + returnCommand); writer.write(returnCommand); writer.flush(); }
private String getHelpObject(BufferedReader reader) throws IOException { String objectId = reader.readLine(); String pattern = (String) Protocol.getObject(reader.readLine(), this.gateway); String shortName = safeReadLine(reader, false); // EoC reader.readLine(); String returnCommand; try { Object obj = gateway.getObject(objectId); Py4JClass clazz = Py4JClass.buildClass(obj.getClass(), true); boolean isShortName = Protocol.getBoolean(shortName); String helpPage = HelpPageGenerator.getHelpPage(clazz, pattern, isShortName); ReturnObject rObject = gateway.getReturnObject(helpPage); returnCommand = Protocol.getOutputCommand(rObject); } catch (Exception e) { returnCommand = Protocol.getOutputErrorCommand(e); } return returnCommand; }
@Override public void execute(String commandName, BufferedReader reader, BufferedWriter writer) throws Py4JException, IOException { String subCommand = safeReadLine(reader);
private String getHelpClass(BufferedReader reader) throws IOException { String className = reader.readLine(); String pattern = (String) Protocol.getObject(reader.readLine(), this.gateway); String shortName = safeReadLine(reader, false); // EoC reader.readLine(); String returnCommand; try { Py4JClass clazz = Py4JClass.buildClass(ReflectionUtil.classForName(className), true); boolean isShortName = Protocol.getBoolean(shortName); String helpPage = HelpPageGenerator.getHelpPage(clazz, pattern, isShortName); ReturnObject rObject = gateway.getReturnObject(helpPage); returnCommand = Protocol.getOutputCommand(rObject); } catch (Exception e) { returnCommand = Protocol.getOutputErrorCommand(e); } return returnCommand; }