Example #1
0
    def unlisten_multicast_group(self,
                                 multicast_address,
                                 source=None,
                                 network_interface=None,
                                 handler=None):
        """Leaves a multicast group and so stop listen for packets send to it on the given network interface.
        The handler is notified once the operation completes.

        @param   multicast_address:     the address of the multicast group to leave
        @param   source:                the address of the source for which we will stop listen for mulicast packets
        @param   network_interface:     the network interface on which to stop listen for packets.
        @param   handler:               then handler to notify once the operation completes
        @return  self:                  returns itself for method-chaining
        """
        def converter(server):
            return self

        if network_interface is not None and source is not None:
            self.java_obj.unlistenMulticastGroup(
                multicast_address, network_interface, source,
                AsyncHandler(handler, converter))
        else:
            self.java_obj.unlistenMulticastGroup(
                multicast_address, AsyncHandler(handler, converter))

        return self
Example #2
0
    def block_multicast_group(self,
                              multicast_address,
                              source_to_block,
                              network_interface=None,
                              handler=None):
        """Block the given source_to_block address for the given multicast_address on the given network_interface.
        The handler is notified once the operation completes.

        @param   multicast_address:     the address for which you want to block the source_to_block
        @param   source_to_block:       the source address which should be blocked. You will not receive an multicast packets
                                        for it anymore.
        @param   network_interface:     the network interface on which the block should be done
        @param   handler:           then handler to notify once the operation completes
        @return  self:              returns itself for method-chaining
        """
        def converter(server):
            return self

        if network_interface is not None:
            self.java_obj.blockMulticastGroup(multicast_address,
                                              network_interface,
                                              source_to_block,
                                              AsyncHandler(handler, converter))
        else:
            self.java_obj.blockMulticastGroup(multicast_address,
                                              source_to_block,
                                              AsyncHandler(handler, converter))
        return self
Example #3
0
    def open(self,
             path,
             perms=None,
             read=True,
             write=True,
             create_new=True,
             flush=False,
             handler=None):
        """Open a file on the file system, asynchronously.

        Keyword arguments:
        @param path: path of the file to open.
        @param perms: if the file does not exist and create_new is true, then the file will be created with these permissions.
        @param read: open the file for reading?
        @param write: open the file for writing?
        @param create_new: Create the file if it doesn't already exist?
        @param flush: whenever any data is written to the file, flush all changes to permanent storage immediately?
        @param handler: the function to call when complete
        """
        def converter(f):
            return AsyncFile(f)

        self.java_obj.open(path, perms, read, write, create_new, flush,
                           AsyncHandler(handler, converter))
        return self
Example #4
0
    def unlink(self, link, handler):
        """Unlink a hard link.

        Keyword arguments:
        @param link: path of the link to unlink.
        """
        self.java_obj.unlink(link, AsyncHandler(handler))
        return self
Example #5
0
    def copy(self, frm, to, handler):
        """Copy a file, asynchronously. The copy will fail if from does not exist, or if to already exists.

        Keyword arguments:
        @param frm: path of file to copy
        @param to: path of file to copy to
        @param handler: the handler which is called on completion."""
        self.java_obj.copy(frm, to, AsyncHandler(handler))
        return self
Example #6
0
    def read_symlink(self, link, handler):
        """Read a symbolic link, asynchronously. I.e. tells you where the symbolic link points.

        Keyword arguments:
        @param link: path of the link to read.
        @param handler: the function to call when complete
        """
        self.java_obj.readSymlink(link, AsyncHandler(handler))
        return self
Example #7
0
    def exists(self, path, handler):
        """Check if  a file exists, asynchronously.

        Keyword arguments:
        @param path: Path of the file to check.
        @param handler: the function to call when complete
        """
        self.java_obj.exists(path, AsyncHandler(handler))
        return self
Example #8
0
    def move(self, frm, to, handler):
        """Move a file, asynchronously. The move will fail if from does not exist, or if to already exists.

        Keyword arguments:
        @param frm: Path of file to move
        @param to: Path of file to move to
        @param handler: the function to call when complete
        """
        self.java_obj.move(frm, to, AsyncHandler(handler))
        return self
Example #9
0
    def resolve_cname(self, name, handler):
        """Try to resolve all CNAME records for the given name. The handler will get notified with an array hold them.

        Keyword arguments:
        @param name:    The name to resolve
        @param handler: The handler to notify once the response was received or a failure was detected
        @return:        Itself for method-chaining.
        """
        self.java_obj.resolveCNAME(name, AsyncHandler(handler))
        return self
Example #10
0
    def truncate(self, path, len, handler):
        """Truncate a file, asynchronously. The move will fail if path does not exist.

        Keyword arguments:
        @param path: Path of file to truncate
        @param len: Length to truncate file to. Will fail if len < 0. If len > file size then will do nothing.
        @param handler: the function to call when complete
        """
        self.java_obj.truncate(path, len, AsyncHandler(handler))
        return self
Example #11
0
    def symlink(self, link, existing, handler):
        """Create a symbolic link, asynchronously.

        Keyword arguments:
        @param link: Path of the link to create.
        @param existing: Path of where the link points to.
        @param handler: the function to call when complete
        """
        self.java_obj.symlink(link, existing, AsyncHandler(handler))
        return self
Example #12
0
    def resolve_ptr(self, name, handler):
        """Try to resolve the PTR record for the given name.

        Keyword arguments:
        @param name:    The name to resolve
        @param handler: The handler to notify once the response was received or a failure was detected
        @return:        Itself for method-chaining.
        """
        self.java_obj.resolvePTR(name, AsyncHandler(handler))
        return self
Example #13
0
    def write_buffer_to_file(self, path, buffer, handler):
        """Write a  as the entire contents of a file, asynchronously.

        Keyword arguments:
        @param path: path of the file to write.
        @param buffer: the Buffer to write
        @param handler: the function to call when complete
        """
        self.java_obj.writeFile(path, buffer, AsyncHandler(handler))
        return self
Example #14
0
    def delete(self, path, handler):
        """Delete a file on the file system, asynchronously.
        The delete will fail if the file does not exist, or is a directory and is not empty.

        Keyword arguments:
        @param path: path of the file to delete.
        @param handler: the function to call when complete
        """
        self.java_obj.delete(path, AsyncHandler(handler))
        return self
Example #15
0
    def create_file(self, path, perms=None, handler=None):
        """Create a new empty file, asynchronously.

        Keyword arguments:
        @param path: path of the file to create.
        @param perms: the file will be created with these permissions.
        @param handler: the function to call when complete
        """
        self.java_obj.createFile(path, perms, AsyncHandler(handler))
        return self
Example #16
0
    def mkdir_with_parents(self, path, perms=None, handler=None):
        """Create a directory, and create all it's parent directories if they do not already exist, asynchronously.
        The create will fail if the directory already exists.

        Keyword arguments:
        @param path: path of the directory to create.
        @param perms: a permission string of the form rwxr-x--- to give the created directory(ies).
        """
        self.java_obj.mkdir(path, perms, True, AsyncHandler(handler))
        return self
Example #17
0
    def chown(self, path, user, group, handler=None):
        """Change the ownership on a file, asynchronously.

        Keyword arguments:
        @param path: path of file to change ownership
        @param user: the user to which to change
        @param group: the group to which to change
        @param handler: the function to call when complete
        """
        self.java_obj.chown(path, user, group, AsyncHandler(handler))
        return self
Example #18
0
    def delete_recursive(self, path, handler):
        """Delete a file on the file system recursively, asynchronously.
        The delete will fail if the file does not exist. If the file is a directory the entire directory contents
        will be deleted recursively.

        Keyword arguments:
        @param path: path of the file to delete.
        @param handler: the function to call when complete
        """
        self.java_obj.delete(path, True, AsyncHandler(handler))
        return self
Example #19
0
    def lookup_6(self, name, handler):
        """Try to lookup the AAAA (ipv6) record for the given name.

            Keyword arguments:
            @param name:    The name to resolve
            @param handler: The handler to notify once the response was received or a failure was detected
            @return:        Itself for method-chaining.
        """
        self.java_obj.lookup6(name,
                              AsyncHandler(handler, self.__address_converter))
        return self
Example #20
0
 def handleAuthorise(self, message, session_id, handler):
     if self._authorise_handler is not None:
         async_handler = AsyncHandler(handler)
         def func(result):
             if isinstance(result, Exception):
                 org.vertx.java.core.impl.DefaultFutureResult().setHandler(handler).setFailure(result)
             else:
                 org.vertx.java.core.impl.DefaultFutureResult().setHandler(handler).setResult(bool(result))
         result = self._authorise_handler(map_from_java(message), session_id, func)
         return result if result is not None else True
     return True
Example #21
0
    def fs_props(self, path, handler):
        """Get properties for the file system, asynchronously.

        Keyword arguments:
        @param path: Path in the file system.
        @param handler: the function to call when complete
        """
        def converter(props):
            return FSProps(props)

        self.java_obj.fsProps(path, AsyncHandler(handler, converter))
        return self
Example #22
0
    def props(self, path, handler):
        """Get file properties for a file, asynchronously.

        Keyword arguments:
        @param path: path to file
        @param handler: the function to call when complete
        """
        def converter(obj):
            return FileProps(obj)

        self.java_obj.props(path, AsyncHandler(handler, converter))
        return self
Example #23
0
    def reverse_lookup(self, ip, handler):
        """ Try to do a reverse lookup of an ipaddress. This is basically the same as doing trying to resolve a PTR record
        but allows you to just pass in the ipaddress and not a valid ptr query string.

        Keyword arguments:
        @param ip:      The ip to resolve
        @param handler: The handler to notify once the response was received or a failure was detected
        @return:        Itself for method-chaining.
        """
        self.java_obj.reverseLookup(
            ip, AsyncHandler(handler, self.__host_converter))
        return self
Example #24
0
    def read_file_as_buffer(self, path, handler):
        """Read the contents of an entire file as a Buffer, asynchronously.

        Keyword arguments:
        @param path: path of the file to read.
        @param handler: the function to call when complete
        """
        def converter(buffer):
            return Buffer(buffer)

        self.java_obj.readFile(path, AsyncHandler(handler, converter))
        return self
Example #25
0
    def read_dir(self, path, filter=None, handler=None):
        """Read a directory, i.e. list it's contents, asynchronously.
        The read will fail if the directory does not exist.

        Keyword arguments:
        @param path: path of the directory to read.
        @param filter: a regular expression to filter out the contents of the directory. If the filter is not nil
        then only files which match the filter will be returned.
        @param handler: the function to call when complete
        """
        self.java_obj.readDir(path, filter, AsyncHandler(handler))
        return self
Example #26
0
    def chmod(self, path, perms, dir_perms=None, handler=None):
        """Change the permissions on a file, asynchronously. If the file is directory then all contents will also have their permissions changed recursively.

        Keyword arguments:
        @param path: path of file to change permissions
        @param perms: a permission string of the form rwxr-x--- as specified in http://download.oracle.com/javase/7/docs/api/java/nio/file/attribute/PosixFilePermissions.html. This is
        used to set the permissions for any regular files (not directories).
        @param dir_perms: a permission string of the form rwxr-x---. Used to set permissions for regular files.
        @param handler: the function to call when complete
        """
        self.java_obj.chmod(path, perms, dir_perms, AsyncHandler(handler))
        return self
Example #27
0
    def mkdir(self, path, perms=None, handler=None):
        """Create a directory, asynchronously.
        The create will fail if the directory already exists, or if it contains parent directories which do not already
        exist.

        Keyword arguments:
        @param path: path of the directory to create.
        @param perms: a permission string of the form rwxr-x--- to give directory.
        @param handler: the function to call when complete
        """
        self.java_obj.mkdir(path, perms, AsyncHandler(handler))
        return self
Example #28
0
    def copy_recursive(self, frm, to, handler):
        """Copy a file recursively, asynchronously. The copy will fail if from does not exist, or if to already exists and is not empty.
        If the source is a directory all contents of the directory will be copied recursively, i.e. the entire directory
        tree is copied.

        Keyword arguments:
        @param frm: path of file to copy
        @param to: path of file to copy to
        @param handler: the function to call when complete
        """
        self.java_obj.copy(frm, to, True, AsyncHandler(handler))
        return self
Example #29
0
    def flush(self, handler=None):
        """Flush any writes made to this file to underlying persistent storage, asynchronously.
        If the file was opened with flush set to true then calling this method will have no effect.
        Keyword arguments:

        @param handler: the handler which is called on completion.
        """
        if handler is None:
            Future(self.java_obj.flush())
        else:
            Future(self.java_obj.flush(AsyncHandler(handler)))
        return self
Example #30
0
def deploy_module(module_name, config=None, instances=1, handler=None):
    """Deploy a module. The actual deploy happens asynchronously

    Keyword arguments:
    @param module_name: The name of the module to deploy
    @param config: dict configuration for the module
    @param instances: Number of instances to deploy
    @param handler: an handler that will be called when deploy has completed
    """
    if config != None:
        config = org.vertx.java.core.json.JsonObject(map_to_java(config))
    org.vertx.java.platform.impl.JythonVerticleFactory.container.deployModule(
        module_name, config, instances, AsyncHandler(handler))