package test; import com.perforce.p4java.client.IClient; import com.perforce.p4java.core.file.FileSpecBuilder; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.option.client.ParallelSyncOptions; import com.perforce.p4java.option.client.SyncOptions; import com.perforce.p4java.server.IOptionsServer; import java.io.PrintStream; import java.util.Arrays; import java.util.List; /** * * * Testing symlink sync * * @author jbrown */ public class StreamingSync { /** * @param args the command line arguments * p4javassl://host:port * client * user * */ public static void main(String[] args) { boolean goodSyntax = true; if (args.length < 5) { System.out.println("Only " + args.length + " provided."); goodSyntax = false; } if (!goodSyntax) { printSyntax(); System.exit(1); } StreamingSync obj = new StreamingSync(); try { obj.doSync(args); } catch (Exception ex) { ex.printStackTrace(System.out); } } public static void printSyntax() { System.out.println("test.StreamingSync <p4java uri> <user> <password> <client> <filespec ...>"); System.out.println("The user must already be logged in if password is zero-length string."); System.out.println(" optional: -Dhave=false don't populate have table"); System.out.println(" optional: -Dthreads=N number of parallel threads"); System.out.println(" optional: -Dcharset=<charset> before test.StreamingSync"); } String uri; String clientName; String userName; String passWord; String[] fileSpec; IOptionsServer server; /* perform the sync * */ private void doSync(String[] args) throws Exception { this.uri = args[0]; this.userName = args[1]; this.passWord = args[2]; this.clientName = args[3]; this.fileSpec = Arrays.copyOfRange(args, 4, args.length); // args[4]; System.out.println("Java version: " + System.getProperty("java.version")); server = ConnectFactory.getServer(uri, userName, passWord, clientName); System.out.println("Default JVM Charset: " + server.getCharsetName()); IClient iclient = server.getCurrentClient(); System.out.println("Charset: " + server.getCharsetName()); // Sync files with asynchronous callback and parallel if enabled to SyncStreamingCallback callback = new SyncStreamingCallback(server); PrintStream out = System.out; callback.setOutput(out); // sync options SyncOptions syncOpts = new SyncOptions(); Boolean ob = Boolean.valueOf(System.getProperty("have", "true")); System.out.println("Populate have list: " + ob); syncOpts.setServerBypass(!ob); String charset = System.getProperty("charset"); if (charset != null) { System.out.println("Setting charset to " + charset); server.setCharsetName(charset); System.out.println("server.getCharsetName() is now: " + server.getCharsetName()); } // determine number of parallel threads String threadString = System.getProperty("threads", "-1"); int threads = -1; try { threads = Integer.parseInt(threadString); } catch (NumberFormatException e) { System.out.println("threads not integer: " + threadString); threads = -1; } if (threads >= 0) { System.out.println("Using threads: " + threads); } else { System.out.println("Using threads: server determines."); } TimeCommand timer = new TimeCommand(); timer.start(); synchronized (callback) { List<IFileSpec> files = FileSpecBuilder.makeFileSpecList(fileSpec); ParallelSyncOptions parallelOpts = new ParallelSyncOptions(); // use server's decision on number of threads if threads < 0 if (threads >= 0) { parallelOpts.setMinumumSize(1024); parallelOpts.setMinimum(1); parallelOpts.setNumberOfThreads(threads); System.out.println("ParallelOpts= " + parallelOpts.toString()); iclient.syncParallel(files, syncOpts, callback, 0, parallelOpts); } else { iclient.sync(files, syncOpts, callback, 0); } while (!callback.isDone()) { callback.wait(); } if (callback.isFail()) { throw new P4JavaException(callback.getException()); } out.println("Files affected: " + callback.getResultCount()); out.flush(); server.disconnect(); } out.println("Sync finished: " + timer); out.flush(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 28709 | Joel Brown |
Allow setting character encoding (charset) with syncs with the Java System Property -Dcharset=<value> |
||
#4 | 27754 | Joel Brown | Allow to specify number of parallel threads. | ||
#3 | 27671 | Joel Brown | Revise to use serverBypass | ||
#2 | 27670 | Joel Brown |
Add to Sync and Streaming Sync the ability to not populate the have table java -Dhave=false -cp JenkinsOps.jar .... |
||
#1 | 26533 | Joel Brown |
Add Streaming Sync test. This will use a streaming sync call similar to what P4 Plugin for Jenkins uses. |