/[svn]/jsampler/trunk/src/org/jsampler/task/InstrumentsDb.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/task/InstrumentsDb.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1867 - (show annotations) (download)
Mon Mar 16 22:12:32 2009 UTC (15 years, 1 month ago) by iliev
File size: 27394 byte(s)
* proper handling of connection failures
* renamed Channels Panels to Channel Lanes
* code cleanup

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of JSampler.
7 *
8 * JSampler is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * JSampler is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with JSampler; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.jsampler.task;
24
25 import org.jsampler.CC;
26
27 import org.linuxsampler.lscp.DbDirectoryInfo;
28 import org.linuxsampler.lscp.DbInstrumentInfo;
29 import org.linuxsampler.lscp.DbSearchQuery;
30 import org.linuxsampler.lscp.ScanJobInfo;
31
32 import static org.jsampler.JSI18n.i18n;
33 import static org.linuxsampler.lscp.Client.ScanMode;
34
35 /**
36 * Provides the instruments database specific tasks.
37 * @author Grigor Iliev
38 */
39 public class InstrumentsDb {
40
41 /** Forbits the instantiation of this class. */
42 private InstrumentsDb() { }
43
44 /**
45 * This task retrieves the number of directories in the specified directory.
46 */
47 public static class GetDirectoryCount extends EnhancedTask<Integer> {
48 private String dir;
49 private boolean recursive;
50
51 /**
52 * Creates a new instance of <code>GetDirectoryCount</code>.
53 * @param dir The absolute path name of the directory.
54 * @param recursive If <code>true</code>, the number of all directories
55 * in the specified subtree will be returned.
56 */
57 public
58 GetDirectoryCount(String dir, boolean recursive) {
59 setTitle("InstrumentsDb.GetDirectoryCount_task");
60 setDescription(i18n.getMessage("InstrumentsDb.GetDirectoryCount.desc"));
61 this.dir = dir;
62 this.recursive = recursive;
63 }
64
65 /** The entry point of the task. */
66 @Override
67 public void
68 exec() throws Exception {
69 setResult(CC.getClient().getDbDirectoryCount(dir, recursive));
70 }
71 }
72
73 /**
74 * This task retrieves the number of instruments in the specified directory.
75 */
76 public static class GetInstrumentCount extends EnhancedTask<Integer> {
77 private String dir;
78 private boolean recursive;
79
80 /**
81 * Creates a new instance of <code>GetInstrumentCount</code>.
82 * @param dir The absolute path name of the directory.
83 * @param recursive If <code>true</code>, the number of all instruments
84 * in the specified subtree will be returned.
85 */
86 public
87 GetInstrumentCount(String dir, boolean recursive) {
88 setTitle("InstrumentsDb.GetInstrumentCount_task");
89 setDescription(i18n.getMessage("InstrumentsDb.GetInstrumentCount.desc"));
90 this.dir = dir;
91 this.recursive = recursive;
92 }
93
94 /** The entry point of the task. */
95 @Override
96 public void
97 exec() throws Exception {
98 setResult(CC.getClient().getDbInstrumentCount(dir, recursive));
99 }
100 }
101
102 /**
103 * This task retrieves the list of directories in the specified directory.
104 */
105 public static class GetDrectories extends EnhancedTask<DbDirectoryInfo[]> {
106 private String dir;
107
108 /**
109 * Creates a new instance of <code>GetDrectories</code>.
110 * @param dir The absolute path name of the directory.
111 */
112 public
113 GetDrectories(String dir) {
114 setTitle("InstrumentsDb.GetDrectories_task");
115 setDescription(i18n.getMessage("InstrumentsDb.GetDrectories.desc"));
116 this.dir = dir;
117 }
118
119 /** The entry point of the task. */
120 @Override
121 public void
122 exec() throws Exception { setResult(CC.getClient().getDbDirectories(dir)); }
123
124 public String
125 getDirectory() { return dir; }
126
127 /**
128 * Used to decrease the traffic. All task in the queue
129 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
130 * @see org.jsampler.CC#addTask
131 */
132 @Override
133 public boolean
134 equals(Object obj) {
135 if(obj == null) return false;
136 if(!(obj instanceof GetDrectories)) return false;
137 String d = ((GetDrectories)obj).getDirectory();
138 if(getDirectory() == null) {
139 return d == null;
140 }
141 if(!getDirectory().equals(d)) return false;
142
143 return true;
144 }
145 }
146
147
148 /**
149 * This task retrieves information about a directory.
150 */
151 public static class GetDrectory extends EnhancedTask<DbDirectoryInfo> {
152 private String dir;
153
154 /**
155 * Creates a new instance of <code>GetDrectory</code>.
156 * @param dir The absolute path name of the directory.
157 */
158 public
159 GetDrectory(String dir) {
160 setTitle("InstrumentsDb.GetDrectory_task");
161 setDescription(i18n.getMessage("InstrumentsDb.GetDrectory.desc"));
162 this.dir = dir;
163 }
164
165 /** The entry point of the task. */
166 @Override
167 public void
168 exec() throws Exception { setResult(CC.getClient().getDbDirectoryInfo(dir)); }
169 }
170
171 /**
172 * This task creates a new directory.
173 */
174 public static class CreateDirectory extends EnhancedTask {
175 private String dir;
176
177 /**
178 * Creates a new instance of <code>CreateDirectory</code>.
179 * @param dir The absolute path name of the directory to add.
180 */
181 public
182 CreateDirectory(String dir) {
183 setTitle("InstrumentsDb.CreateDirectory_task");
184 setDescription(i18n.getMessage("InstrumentsDb.CreateDirectory.desc"));
185 this.dir = dir;
186 }
187
188 /** The entry point of the task. */
189 @Override
190 public void
191 exec() throws Exception { CC.getClient().addDbDirectory(dir); }
192 }
193
194 /**
195 * This task renames the specified directory.
196 */
197 public static class RenameDirectory extends EnhancedTask {
198 private String dir;
199 private String newName;
200
201 /**
202 * Creates a new instance of <code>RenameDirectory</code>.
203 * @param dir The absolute path name of the directory to rename.
204 * @param newName The new name for the specified directory.
205 */
206 public
207 RenameDirectory(String dir, String newName) {
208 setTitle("InstrumentsDb.RenameDirectory_task");
209 setDescription(i18n.getMessage("InstrumentsDb.RenameDirectory.desc"));
210 this.dir = dir;
211 this.newName = newName;
212 }
213
214 /** The entry point of the task. */
215 @Override
216 public void
217 exec() throws Exception { CC.getClient().renameDbDirectory(dir, newName); }
218 }
219
220 /**
221 * This task changes the description of a directory.
222 */
223 public static class SetDirectoryDescription extends EnhancedTask {
224 private String dir;
225 private String desc;
226
227 /**
228 * Creates a new instance of <code>SetDirectoryDescription</code>.
229 * @param dir The absolute path name of the directory.
230 * @param desc The new description for the directory.
231 */
232 public
233 SetDirectoryDescription(String dir, String desc) {
234 setTitle("InstrumentsDb.SetDirectoryDescription_task");
235 String s = i18n.getMessage("InstrumentsDb.SetDirectoryDescription.desc");
236 setDescription(s);
237 this.dir = dir;
238 this.desc = desc;
239 }
240
241 /** The entry point of the task. */
242 @Override
243 public void
244 exec() throws Exception {
245 CC.getClient().setDbDirectoryDescription(dir, desc);
246 }
247 }
248
249 /**
250 * This task removes the specified directories.
251 */
252 public static class RemoveDirectories extends EnhancedTask {
253 private DbDirectoryInfo[] directories;
254
255 /**
256 * Creates a new instance of <code>RemoveDirectories</code>.
257 * @param directories The directories to remove.
258 */
259 public
260 RemoveDirectories(DbDirectoryInfo[] directories) {
261 super(true);
262 setTitle("InstrumentsDb.RemoveDirectories_task");
263 setDescription(i18n.getMessage("InstrumentsDb.RemoveDirectories.desc"));
264 this.directories = directories;
265 }
266
267 /** The entry point of the task. */
268 @Override
269 public void
270 exec() throws Exception { removeDirectories(); }
271
272 private void
273 removeDirectories() throws Exception {
274 if(directories == null || directories.length == 0) return;
275 if(directories.length == 1) {
276 String path = directories[0].getDirectoryPath();
277 CC.getClient().removeDbDirectory(path, true);
278 } else {
279 String[] dirs = new String[directories.length];
280 for(int i = 0; i < directories.length; i++) {
281 dirs[i] = directories[i].getDirectoryPath();
282 }
283
284 CC.getClient().removeDbDirectories(dirs, true);
285 }
286 }
287 }
288
289 /**
290 * This task finds all directories in the specified directory
291 * that corresponds to the provided search criterias.
292 */
293 public static class FindDirectories extends EnhancedTask<DbDirectoryInfo[]> {
294 private String dir;
295 private DbSearchQuery query;
296
297 /**
298 * Creates a new instance of <code>FindDirectories</code>.
299 * @param dir The absolute path name of the directory.
300 * @param query Provides the search criterias.
301 */
302 public
303 FindDirectories(String dir, DbSearchQuery query) {
304 setTitle("InstrumentsDb.FindDirectories_task");
305 setDescription(i18n.getMessage("InstrumentsDb.FindDirectories.desc"));
306 this.dir = dir;
307 this.query = query;
308 }
309
310 /** The entry point of the task. */
311 @Override
312 public void
313 exec() throws Exception {
314 setResult(CC.getClient().findDbDirectories(dir, query));
315 }
316 }
317
318 /**
319 * This task retrieves the list of instruments in the specified directory.
320 */
321 public static class GetInstruments extends EnhancedTask<DbInstrumentInfo[]> {
322 private String dir;
323
324 /**
325 * Creates a new instance of <code>GetInstruments</code>.
326 * @param dir The absolute path name of the directory.
327 */
328 public
329 GetInstruments(String dir) {
330 super(true);
331 setTitle("InstrumentsDb.GetInstruments_task");
332 setDescription(i18n.getMessage("InstrumentsDb.GetInstruments.desc"));
333 this.dir = dir;
334 }
335
336 /** The entry point of the task. */
337 @Override
338 public void
339 exec() throws Exception { setResult(CC.getClient().getDbInstruments(dir)); }
340
341 public String
342 getDirectory() { return dir; }
343
344 /**
345 * Used to decrease the traffic. All task in the queue
346 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
347 * @see org.jsampler.CC#addTask
348 */
349 @Override
350 public boolean
351 equals(Object obj) {
352 if(obj == null) return false;
353 if(!(obj instanceof GetInstruments)) return false;
354 String d = ((GetInstruments)obj).getDirectory();
355 if(getDirectory() == null) {
356 return d == null;
357 }
358 if(!getDirectory().equals(d)) return false;
359 return true;
360 }
361 }
362
363 /**
364 * This task retrieves information about an instrument.
365 */
366 public static class GetInstrument extends EnhancedTask<DbInstrumentInfo> {
367 private String instr;
368
369 /**
370 * Creates a new instance of <code>GetInstrument</code>.
371 * @param instr The absolute path name of the instrument.
372 */
373 public
374 GetInstrument(String instr) {
375 setTitle("InstrumentsDb.GetInstrument_task");
376 setDescription(i18n.getMessage("InstrumentsDb.GetInstrument.desc"));
377 this.instr = instr;
378 }
379
380 /** The entry point of the task. */
381 @Override
382 public void
383 exec() throws Exception {
384 setResult(CC.getClient().getDbInstrumentInfo(instr));
385 }
386 }
387
388 /**
389 * This task finds all instruments in the specified directory
390 * that corresponds to the provided search criterias.
391 */
392 public static class FindInstruments extends EnhancedTask<DbInstrumentInfo[]> {
393 private String dir;
394 private DbSearchQuery query;
395
396 /**
397 * Creates a new instance of <code>FindInstruments</code>.
398 * @param dir The absolute path name of the directory.
399 * @param query Provides the search criterias.
400 */
401 public
402 FindInstruments(String dir, DbSearchQuery query) {
403 setTitle("InstrumentsDb.FindInstruments_task");
404 setDescription(i18n.getMessage("InstrumentsDb.FindInstruments.desc"));
405 this.dir = dir;
406 this.query = query;
407 }
408
409 /** The entry point of the task. */
410 @Override
411 public void
412 exec() throws Exception {
413 setResult(CC.getClient().findDbInstruments(dir, query));
414 }
415 }
416
417 /**
418 * This task renames the specified instrument.
419 */
420 public static class RenameInstrument extends EnhancedTask {
421 private String instr;
422 private String newName;
423
424 /**
425 * Creates a new instance of <code>RenameInstrument</code>.
426 * @param instr The absolute path name of the instrument to rename.
427 * @param newName The new name for the specified instrument.
428 */
429 public
430 RenameInstrument(String instr, String newName) {
431 setTitle("InstrumentsDb.RenameInstrument_task");
432 setDescription(i18n.getMessage("InstrumentsDb.RenameInstrument.desc"));
433 this.instr = instr;
434 this.newName = newName;
435 }
436
437 /** The entry point of the task. */
438 @Override
439 public void
440 exec() throws Exception { CC.getClient().renameDbInstrument(instr, newName); }
441 }
442
443 /**
444 * This task changes the description of an instrument.
445 */
446 public static class SetInstrumentDescription extends EnhancedTask {
447 private String instr;
448 private String desc;
449
450 /**
451 * Creates a new instance of <code>SetInstrumentDescription</code>.
452 * @param instr The absolute path name of the instrument.
453 * @param desc The new description for the instrument.
454 */
455 public
456 SetInstrumentDescription(String instr, String desc) {
457 setTitle("InstrumentsDb.SetInstrumentDescription_task");
458 String s = i18n.getMessage("InstrumentsDb.SetInstrumentDescription.desc");
459 setDescription(s);
460 this.instr = instr;
461 this.desc = desc;
462 }
463
464 /** The entry point of the task. */
465 @Override
466 public void
467 exec() throws Exception {
468 CC.getClient().setDbInstrumentDescription(instr, desc);
469 }
470 }
471
472 /**
473 * This task removes the specified instruments.
474 */
475 public static class RemoveInstruments extends EnhancedTask {
476 private DbInstrumentInfo[] instruments;
477
478 /**
479 * Creates a new instance of <code>RemoveInstruments</code>.
480 * @param instruments The instruments to remove.
481 */
482 public
483 RemoveInstruments(DbInstrumentInfo[] instruments) {
484 super(true);
485 setTitle("InstrumentsDb.RemoveInstruments_task");
486 setDescription(i18n.getMessage("InstrumentsDb.RemoveInstruments.desc"));
487 this.instruments = instruments;
488 }
489
490 /** The entry point of the task. */
491 @Override
492 public void
493 exec() throws Exception { removeInstruments(); }
494
495 private void
496 removeInstruments() throws Exception {
497 if(instruments == null || instruments.length == 0) return;
498 if(instruments.length == 1) {
499 String path = instruments[0].getInstrumentPath();
500 CC.getClient().removeDbInstrument(path);
501 } else {
502 String[] instrs = new String[instruments.length];
503 for(int i = 0; i < instruments.length; i++) {
504 instrs[i] = instruments[i].getInstrumentPath();
505 }
506
507 CC.getClient().removeDbInstruments(instrs);
508 }
509 }
510 }
511
512 /**
513 * This task adds instruments from an instrument file to the instruments database.
514 */
515 public static class AddInstrumentsFromFile extends EnhancedTask<Integer> {
516 private String dbDir;
517 private String filePath;
518 private int instrIndex;
519
520 /**
521 * Creates a new instance of <code>AddInstrumentsFromFile</code>.
522 * @param dbDir The absolute path name of the database directory
523 * in which all instruments from the specified instrument file will be added.
524 * @param filePath The absolute path name of the instrument file.
525 */
526 public
527 AddInstrumentsFromFile(String dbDir, String filePath) {
528 this(dbDir, filePath, -1);
529 }
530
531 /**
532 * Creates a new instance of <code>AddInstrumentsFromFile</code>.
533 * @param dbDir The absolute path name of the database directory
534 * in which the specified instrument will be added.
535 * @param filePath The absolute path name of the instrument file.
536 * @param instrIndex The index of the instrument
537 * (in the given instrument file) to add. If -1 is specified, all
538 * instruments in the given instrument file will be added.
539 */
540 public
541 AddInstrumentsFromFile(String dbDir, String filePath, int instrIndex) {
542 setTitle("InstrumentsDb.AddInstrumentsFromFile_task");
543 String s = i18n.getMessage("InstrumentsDb.AddInstrumentsFromFile.desc");
544 setDescription(s);
545 this.dbDir = dbDir;
546 this.filePath = filePath;
547 this.instrIndex = instrIndex;
548 }
549
550 /** The entry point of the task. */
551 @Override
552 public void
553 exec() throws Exception {
554 int i;
555 if(instrIndex != -1) {
556 i = CC.getClient().addDbInstrument (
557 dbDir, filePath, instrIndex, true
558 );
559 } else {
560 i = CC.getClient().addDbInstruments(dbDir, filePath, true);
561 }
562
563 setResult(i);
564 }
565 }
566
567 /**
568 * This task adds instruments from a directory to the instruments database.
569 */
570 public static class AddInstruments extends EnhancedTask<Integer> {
571 private String dbDir;
572 private String fsDir;
573 private boolean flat;
574 private boolean insDir;
575
576 /**
577 * Creates a new instance of <code>AddInstruments</code>.
578 * @param dbDir The absolute path name of the database directory
579 * in which all instruments from the specified directory will be added.
580 * @param fsDir The absolute path name of the file system directory.
581 */
582 public
583 AddInstruments(String dbDir, String fsDir) {
584 this(dbDir, fsDir, false);
585 }
586
587 /**
588 * Creates a new instance of <code>AddInstruments</code>.
589 * @param dbDir The absolute path name of the database directory
590 * in which all instruments from the specified directory will be added.
591 * @param fsDir The absolute path name of the file system directory.
592 * @param flat If <code>true</code>, the respective subdirectory structure
593 * will not be re-created in the supplied database directory.
594 */
595 public
596 AddInstruments(String dbDir, String fsDir, boolean flat) {
597 this(dbDir, fsDir, flat, false);
598 }
599
600 /**
601 * Creates a new instance of <code>AddInstruments</code>.
602 * @param dbDir The absolute path name of the database directory
603 * in which all instruments from the specified directory will be added.
604 * @param fsDir The absolute path name of the file system directory.
605 * @param flat If <code>true</code>, the respective subdirectory structure
606 * will not be re-created in the supplied database directory.
607 * @param insDir If <code>true</code>, a directory will be created for each
608 * instrument file
609 */
610 public
611 AddInstruments(String dbDir, String fsDir, boolean flat, boolean insDir) {
612 setTitle("InstrumentsDb.AddInstruments_task");
613 String s = i18n.getMessage("InstrumentsDb.AddInstruments.desc");
614 setDescription(s);
615 this.dbDir = dbDir;
616 this.fsDir = fsDir;
617 this.flat = flat;
618 this.insDir = insDir;
619 }
620
621 /** The entry point of the task. */
622 @Override
623 public void
624 exec() throws Exception {
625 ScanMode scanMode = flat ? ScanMode.FLAT : ScanMode.RECURSIVE;
626 int i = CC.getClient().addDbInstruments (
627 scanMode, dbDir, fsDir, true, insDir
628 );
629
630 setResult(i);
631 }
632 }
633
634 /**
635 * This task adds instruments from a file system directory (excluding
636 * the instruments in the subdirectories) to the instruments database.
637 */
638 public static class AddInstrumentsNonrecursive extends EnhancedTask<Integer> {
639 private String dbDir;
640 private String fsDir;
641 private boolean insDir;
642
643 /**
644 * Creates a new instance of <code>AddInstrumentsNonrecursive</code>.
645 * @param dbDir The absolute path name of the database directory
646 * in which the instruments from the specified directory (excluding
647 * the instruments in the subdirectories) will be added.
648 * @param fsDir The absolute path name of the file system directory.
649 */
650 public
651 AddInstrumentsNonrecursive(String dbDir, String fsDir) {
652 this(dbDir, fsDir, false);
653 }
654
655 /**
656 * Creates a new instance of <code>AddInstrumentsNonrecursive</code>.
657 * @param dbDir The absolute path name of the database directory
658 * in which the instruments from the specified directory (excluding
659 * the instruments in the subdirectories) will be added.
660 * @param fsDir The absolute path name of the file system directory.
661 * @param insDir If <code>true</code> a directory is add for each
662 * instrument file.
663 */
664 public
665 AddInstrumentsNonrecursive(String dbDir, String fsDir, boolean insDir) {
666 setTitle("InstrumentsDb.AddInstrumentsNonrecursive_task");
667 String s = i18n.getMessage("InstrumentsDb.AddInstrumentsNonrecursive.desc");
668 setDescription(s);
669 this.dbDir = dbDir;
670 this.fsDir = fsDir;
671 this.insDir = insDir;
672 }
673
674 /** The entry point of the task. */
675 @Override
676 public void
677 exec() throws Exception {
678 int i = CC.getClient().addDbInstruments (
679 ScanMode.NON_RECURSIVE, dbDir, fsDir, true, insDir
680 );
681 setResult(i);
682 }
683 }
684
685 /**
686 * This task moves the specified instruments
687 * and directories to the specified location.
688 */
689 public static class Move extends EnhancedTask {
690 private DbDirectoryInfo[] directories;
691 private DbInstrumentInfo[] instruments;
692 private String dest;
693
694 /**
695 * Creates a new instance of <code>Move</code>.
696 * @param directories The directories to move.
697 * @param instruments The instruments to move.
698 * @param dest The absolute path name of the directory where
699 * the specified instruments and directories will be moved to.
700 */
701 public
702 Move(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
703 super(true);
704 setTitle("InstrumentsDb.Move_task");
705 setDescription(i18n.getMessage("InstrumentsDb.Move.desc"));
706 this.directories = directories;
707 this.instruments = instruments;
708 this.dest = dest;
709 }
710
711 /** The entry point of the task. */
712 @Override
713 public void
714 exec() throws Exception {
715 moveInstruments();
716 moveDirectories();
717 }
718
719 private void
720 moveInstruments() throws Exception {
721 if(instruments == null || instruments.length == 0) return;
722 if(instruments.length == 1) {
723 String path = instruments[0].getInstrumentPath();
724 CC.getClient().moveDbInstrument(path, dest);
725 } else {
726 String[] instrs = new String[instruments.length];
727 for(int i = 0; i < instruments.length; i++) {
728 instrs[i] = instruments[i].getInstrumentPath();
729 }
730
731 CC.getClient().moveDbInstruments(instrs, dest);
732 }
733 }
734
735 private void
736 moveDirectories() throws Exception {
737 if(directories == null || directories.length == 0) return;
738 if(directories.length == 1) {
739 String path = directories[0].getDirectoryPath();
740 CC.getClient().moveDbDirectory(path, dest);
741 } else {
742 String[] dirs = new String[directories.length];
743 for(int i = 0; i < directories.length; i++) {
744 dirs[i] = directories[i].getDirectoryPath();
745 }
746
747 CC.getClient().moveDbDirectories(dirs, dest);
748 }
749 }
750 }
751
752 /**
753 * This task copies the specified instruments
754 * and directories to the specified location.
755 */
756 public static class Copy extends EnhancedTask {
757 private DbDirectoryInfo[] directories;
758 private DbInstrumentInfo[] instruments;
759 private String dest;
760
761 /**
762 * Creates a new instance of <code>Copy</code>.
763 * @param directories The directories to copy.
764 * @param instruments The instruments to copy.
765 * @param dest The absolute path name of the directory where
766 * the specified instruments and directories will be copied to.
767 */
768 public
769 Copy(DbDirectoryInfo[] directories, DbInstrumentInfo[] instruments, String dest) {
770 super(true);
771 setTitle("InstrumentsDb.Copy_task");
772 setDescription(i18n.getMessage("InstrumentsDb.Copy.desc"));
773 this.directories = directories;
774 this.instruments = instruments;
775 this.dest = dest;
776 }
777
778 /** The entry point of the task. */
779 @Override
780 public void
781 exec() throws Exception {
782 copyInstruments();
783 copyDirectories();
784 }
785
786 private void
787 copyInstruments() throws Exception {
788 if(instruments == null || instruments.length == 0) return;
789 if(instruments.length == 1) {
790 String path = instruments[0].getInstrumentPath();
791 CC.getClient().copyDbInstrument(path, dest);
792 } else {
793 String[] instrs = new String[instruments.length];
794 for(int i = 0; i < instruments.length; i++) {
795 instrs[i] = instruments[i].getInstrumentPath();
796 }
797
798 CC.getClient().copyDbInstruments(instrs, dest);
799 }
800 }
801
802 private void
803 copyDirectories() throws Exception {
804 if(directories == null || directories.length == 0) return;
805 if(directories.length == 1) {
806 String path = directories[0].getDirectoryPath();
807 CC.getClient().copyDbDirectory(path, dest);
808 } else {
809 String[] dirs = new String[directories.length];
810 for(int i = 0; i < directories.length; i++) {
811 dirs[i] = directories[i].getDirectoryPath();
812 }
813
814 CC.getClient().copyDbDirectories(dirs, dest);
815 }
816 }
817 }
818
819 /**
820 * This task gets a list of all instrument files in the database
821 * that that doesn't exist in the filesystem.
822 */
823 public static class FindLostInstrumentFiles extends EnhancedTask<String[]> {
824
825 /**
826 * Creates a new instance of <code>FindLostInstrumentFiles</code>.
827 */
828 public
829 FindLostInstrumentFiles() {
830 setTitle("InstrumentsDb.FindLostInstrumentFiles_task");
831 setDescription(i18n.getMessage("InstrumentsDb.FindLostInstrumentFiles.desc"));
832 }
833
834 /** The entry point of the task. */
835 @Override
836 public void
837 exec() throws Exception {
838 setResult(CC.getClient().findLostDbInstrumentFiles());
839 }
840 }
841
842 /**
843 * This task substitutes all occurrences of the specified instrument file
844 * in the database, with the specified new path.
845 */
846 public static class SetInstrumentFilePath extends EnhancedTask {
847 private String oldPath;
848 private String newPath;
849
850 /**
851 * Creates a new instance of <code>SetInstrumentFilePath</code>.
852 * @param oldPath The absolute path name of the instrument file to substitute.
853 * @param newPath The new absolute path name.
854 */
855 public
856 SetInstrumentFilePath(String oldPath, String newPath) {
857 setTitle("InstrumentsDb.SetInstrumentFilePath_task");
858 setDescription(i18n.getMessage("InstrumentsDb.SetInstrumentFilePath.desc"));
859 this.oldPath = oldPath;
860 this.newPath = newPath;
861 }
862
863 /** The entry point of the task. */
864 @Override
865 public void
866 exec() throws Exception {
867 CC.getClient().setDbInstrumentFilePath(oldPath, newPath);
868 }
869 }
870
871 /**
872 * This task retrieves information about a scan job.
873 */
874 public static class GetScanJobInfo extends EnhancedTask<ScanJobInfo> {
875 private int jobId;
876
877 /**
878 * Creates a new instance of <code>GetScanJobInfo</code>.
879 * @param jobId The ID of the scan job.
880 */
881 public
882 GetScanJobInfo(int jobId) {
883 setTitle("InstrumentsDb.GetScanJobInfo_task");
884 setDescription(i18n.getMessage("InstrumentsDb.GetScanJobInfo.desc"));
885 this.jobId = jobId;
886 }
887
888 /** The entry point of the task. */
889 @Override
890 public void
891 exec() throws Exception {
892 setResult(CC.getClient().getDbInstrumentsJobInfo(jobId));
893 }
894
895 public int
896 getJobId() { return jobId; }
897
898 /**
899 * Used to decrease the traffic. All task in the queue
900 * equal to this are removed if added using {@link org.jsampler.CC#scheduleTask}.
901 * @see org.jsampler.CC#addTask
902 */
903 @Override
904 public boolean
905 equals(Object obj) {
906 if(obj == null) return false;
907 if(!(obj instanceof GetScanJobInfo)) return false;
908 if(((GetScanJobInfo)obj).getJobId() != getJobId()) return false;
909
910 return true;
911 }
912 }
913
914 /**
915 * This task formats the instruments database.
916 */
917 public static class Format extends EnhancedTask {
918 /**
919 * Formats the instruments database..
920 */
921 public
922 Format() {
923 setTitle("InstrumentsDb.Format_task");
924 String s = i18n.getMessage("InstrumentsDb.Format.desc");
925 setDescription(s);
926 }
927
928 /** The entry point of the task. */
929 @Override
930 public void
931 exec() throws Exception { CC.getClient().formatInstrumentsDb(); }
932 }
933 }

  ViewVC Help
Powered by ViewVC