Documentation

The main documentation of this library can be found in the project's wiki. However, a basic example is listed below, to get you started.

        
            // specify the path to the synchronised folder
            Path rootDir = Paths.get("path/to/synchronised/folder");
            ITreeStorageAdapter storageAdapter = new LocalStorageAdapter(rootDir);

            // initialise the synchronised folder:
            // - create folder for ObjectStore (usually .sync)
            // - create folders for shared files:
            //    - sharedWithOthers (read-write)
            //    - sharedWithOthers (read-only)
            Sync.init(storageAdapter);

            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            KeyPair keyPair = keyGen.genKeyPair();

            RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
            RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();


            ApplicationConfig appConfig = ApplicationConfigFactory.createBootstrapApplicationConfig(
                "Piff Jenkins",
                "ThisIsSafeUseIt",
                "SaltAndPepperMakesTheMealBetter",
                publicKey,
                privateKey,
                ApplicationConfigFactory.getDefaultIgnorePatterns()
            );

            // create a new Sync instance pointing to the root of the
            // specified storage adapter, i.e. path/to/synchronised/folder
            Sync sync = new Sync(storageAdapter);

            // start the node as bootstrap peer (depending on the specified configuration),
            // reconcile state of the synchronised folder with the ObjectStore,
            // reconcile local state with other connected clients of the same user
            NodeLocation nodeLocation = sync.connect(appConfig);


            // share the file lying at relative/path/to/shared/file within
            // the synchronised directory. The absolute path is also
            // path/to/synchronised/folder/relative/path/to/shared/file
            IShareEvent shareEvent = new ShareEvent(
                Paths.get("relative/path/to/shared/file"),
                AccessType.WRITE,
                "Jason Response"
            );

            // get manager to share files and directories
            ISharingSyncer sharingSyncer = sync.getSharingSyncer();
            // contact all nodes of Piff Jenkins, allowing them to
            // update their ObjectStore,
            // then notify one peer of Jason Response
            sharingSyncer.sync(shareEvent);


            // unshare another file previously shared
            IShareEvent unshareEvent = new UnshareEvent(
                Paths.get("previously/shared/file"),
                AccessType.READ,
                "Jason Response"
            );
            // contact all nodes of Piff Jenkins,
            // then notify one client of Jason Response
            sharingSyncer.sync(unshareEvent);


            INode node = sync.getNode();
            // check whether an user is registered, login resp. logout users
            IUserManager userManager = node.getUserManager();
            // access some information stored in the distributed hash table
            INodeManager nodeManager = node.getNodeManager();
            // get file identifiers
            IIdentifierManager identifierManager = node.getIdentifierManager();


            // get event aggregator to dynamically add/remove listeners, modifiers and aggregators
            IEventAggregator eventAggregator = sync.getEventAggregator();


            // get the Object Store of the synchronised folder
            IObjectStore objectStore = sync.getObjectStore();
            // manage PathObjects in the Object Store
            IObjectManager objectManager = objectStore.getObjectManager();
            // manage sharing properties of files and directories
            objectStore.getSharerManager();
            // manage existence of files and directories
            objectStore.getDeleteManager();