GrxProcessManager.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 /*
11  * GrxProcessManager.java
12  *
13  * Copyright (C) 2007 GeneralRobotix, Inc.
14  * All Rights Reserved
15  *
16  * @author Yuichiro Kawasumi (General Robotix, Inc.)
17  * 2004/03/16
18  */
19 
20 package com.generalrobotix.ui.util;
21 
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.InputStreamReader;
27 import java.io.PrintStream;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Set;
32 import java.util.concurrent.ConcurrentLinkedQueue;
33 
34 import jp.go.aist.hrp.simulator.ServerObject;
35 import jp.go.aist.hrp.simulator.ServerObjectHelper;
36 
37 import org.eclipse.swt.widgets.Display;
38 import org.eclipse.core.runtime.IProgressMonitor;
39 
47 
48 @SuppressWarnings("serial")
49 public class GrxProcessManager extends GrxBaseItem{
50  private static GrxProcessManager GrxProcessManagerThis_ = null;
51 
52  private java.util.List<AProcess> process_ = null;
53  private boolean isEnd_ = false;
55  private StringBuffer outputBuffer_ = null;
56  private ConcurrentLinkedQueue<String> lineQueue = null;
57  private Thread thread_ = null;
58  private ProcessInfo nameServerInfo_ = null;
59  private GrxServerManager serverManager_ = null;
60 
61  public GrxProcessManager(String name, GrxPluginManager manager) {
62  super(name, manager);
63  process_ = new java.util.ArrayList<AProcess>();
64  outputBuffer_ = new StringBuffer();
65  lineQueue = new ConcurrentLinkedQueue<String>();
66  GrxProcessManagerThis_ = this;
67  createThread();
68  }
69 
70  public static synchronized void shutDown() {
71  if (GrxProcessManagerThis_ != null) {
72  GrxProcessManagerThis_.autoStop();
73  GrxProcessManagerThis_.stopThread();
74  GrxProcessManagerThis_.process_.clear();
75  GrxProcessManagerThis_.lineQueue.clear();
76  GrxProcessManagerThis_ = null;
77  }
78  }
79 
80  public void setProcessList(GrxServerManager serverManager) {
81  serverManager_ = serverManager;
82  IProgressMonitor monitor = null;
83  setProcessList(monitor);
84  }
85 
86  private void setProcessList(IProgressMonitor monitor){
87  StringBuffer nsHost = new StringBuffer(""); //$NON-NLS-1$
88  StringBuffer nsPort = new StringBuffer(""); //$NON-NLS-1$
89  Activator.refNSHostPort(nsHost, nsPort);
90  String nsOpt = " -ORBInitRef NameService=corbaloc:iiop:" + nsHost + ":" + nsPort + "/NameService"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
92  nameServerInfo_ = serverManager_.getNameServerInfo();
94  if ( isRegistered(nameServerInfo_) ) {
95  if( !isRunning(nameServerInfo_) ){
96  unregister(nameServerInfo_.id);
97  register(nameServerInfo_);
98  }
99  } else {
100  register(nameServerInfo_);
101  }
102  }
103  for(ProcessInfo pi : serverManager_.getServerInfo()){
104  ProcessInfo localPi = pi.clone();
105  for(int i=0; i<localPi.com.size(); i++){
106  if (localPi.useORB) {
107  localPi.com.set(i, localPi.com.get(i) + " " + nsOpt);
108  } else {
109  localPi.com.set(i, localPi.com.get(i));
110  }
111  }
112  if ( isRegistered(localPi) ) {
113  if( !isRunning(localPi) ){
114  unregister(localPi.id);
115  register(localPi);
116  }
117  } else {
118  register(localPi);
119  }
120  }
121  autoStart(monitor);
122  }
123 
124  public boolean isRunning(ProcessInfo pi) {
125  AProcess localProcess = get(pi.id);
126  if (localProcess != null) {
127  return localProcess.isRunning();
128  }
129  return false;
130  }
131 
132  public boolean isRegistered(ProcessInfo pi) {
133  if ( get(pi.id) != null) {
134  return true;
135  }
136  return false;
137  }
138 
139 
140  public boolean register(ProcessInfo pi) {
141  if (get(pi.id) != null) {
142  return false;
143  }
144  pi=pi.expandEnv();
145  process_.add(new AProcess(pi));
146  pi.print();
147  return true;
148  }
149 
150  public boolean unregister(String id) {
151  AProcess p = get(id);
152  if (p == null) {
153  GrxDebugUtil.println("can't find '" + id + "' on processManager."); //$NON-NLS-1$ //$NON-NLS-2$
154  return false;
155  }
156  if (p.isRunning()) {
157  GrxDebugUtil.println(id + " is running."); //$NON-NLS-1$
158  return false;
159  }
160  if (process_.remove(p)) {
161  GrxDebugUtil.println(id + " is unregistered."); //$NON-NLS-1$
162  return true;
163  }
164 
165  return false;
166  };
167 
168  public void clearList() {
169  process_.clear();
170  }
171 
172  public AProcess get(String name) {
173  for (int i = 0; i < process_.size(); i++) {
174  if (get(i).pi_.id.equals(name)) {
175  return get(i);
176  }
177  }
178  return null;
179  }
180 
181  public AProcess get(int n) {
182  if (0 <= n && n < process_.size()) {
183  return process_.get(n);
184  }
185  return null;
186  }
187 
188  public int size() {
189  return process_.size();
190  }
191 
192  public void autoStart(IProgressMonitor monitor) {
193  for (int i = 0; i < process_.size(); i++) {
194  AProcess p = get(i);
195  if (p.pi_.autoStart) {
196  try {
197  (p.getReference())._non_existent();
198  } catch (Exception e) {
199  p.start(null);
200  }
201  }
202  if(monitor != null){
203  monitor.worked(1);
204  }
205  }
206  }
207 
208  public void autoStop() {
209  for (int i = process_.size(); i > 0; i--) {
210  AProcess p = get(i - 1);
211  if (p.pi_.autoStop) {
212  p.stop();
213  }
214  }
215  }
216 
217  private void killall(String pname) {
218  try {
219  if (!System.getProperty("os.name").equals("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
220  return;
221  }
222  ProcessInfo pi = new ProcessInfo();
223  pi.id = "killall"; //$NON-NLS-1$
224  pi.com.add("/usr/bin/killall"); //$NON-NLS-1$
225  pi.dir = "/usr/bin/"; //$NON-NLS-1$
226  pi.autoStart = false;
227  pi.autoStop = true;
228  pi.waitCount = 0;
229  register(pi);
230  GrxDebugUtil.println("\nkillall " + pname + ":"); //$NON-NLS-1$ //$NON-NLS-2$
231  AProcess p = get(pi.id);
232  p.start(pname);
233  p.waitFor();
235  p.clearBuffer();
236  // p.stop();
237  } catch (Exception e) {
238  GrxDebugUtil.printErr("killall:", e); //$NON-NLS-1$
239  }
240  }
241 
242  private String psaxGrep(String str) {
243  try {
244  if (!System.getProperty("os.name").equals("Linux")) { //$NON-NLS-1$ //$NON-NLS-2$
245  return null;
246  }
247  ProcessInfo pi = new ProcessInfo();
248  pi.id = "psaxGrep"; //$NON-NLS-1$
249  pi.com.add("/bin/ps ax"); //$NON-NLS-1$
250  pi.dir = "/bin/"; //$NON-NLS-1$
251  pi.autoStart = false;
252  pi.autoStop = true;
253  pi.waitCount = 0;
254  register(pi);
255  GrxDebugUtil.println("\nps ax:"); //$NON-NLS-1$
256  AProcess p = get(pi.id);
257  p.clearBuffer();
258  p.start(null);
259  p.waitFor();
260  // p.stop();
261  String ret = p.readBuffer();
262  GrxDebugUtil.println(ret);
263  String[] rets = ret.split("\n"); //$NON-NLS-1$
264  ret = ""; //$NON-NLS-1$
265  for (int i = 0; i < rets.length; i++) {
266  if (rets[i].indexOf(str + " ") != -1) { //$NON-NLS-1$
267  ret += rets[i] + "\n"; //$NON-NLS-1$
268  }
269  }
270  return ret;
271  } catch (Exception e) {
272  GrxDebugUtil.printErr("psaxGrep:", e); //$NON-NLS-1$
273  }
274  return null;
275  }
276 
277  public List<Integer> getPID(String processName){
278  int splitNum = 1;
279  List<Integer> ret = new ArrayList<Integer>();
280  String []commands={"tasklist","/NH"}; //$NON-NLS-1$
281  String key = new String(processName + ".exe"); //$NON-NLS-1$
282  Runtime r = Runtime.getRuntime();
283  if (System.getProperty("os.name").equals("Linux") || //$NON-NLS-1$
284  System.getProperty("os.name").equals("Mac OS X")) { //$NON-NLS-1$
285  commands[0] = new String ("/bin/ps"); //$NON-NLS-1$
286  commands[1] = new String ("axh"); //$NON-NLS-1$
287  key = new String("/" + processName);
288  splitNum = 0;
289  }
290 
291  try{
292  Process p = r.exec(commands);
293  p.waitFor();
294  InputStream in = p.getInputStream();
295  p.getOutputStream().toString();
296  BufferedReader br = new BufferedReader(new InputStreamReader(in));
297  String line;
298  while ((line = br.readLine()) != null) {
299  if( line.indexOf(key) >= 0){
300  line = line.replaceAll("^[\\s]+", "");
301  String[] splitLine = line.split("[\\s]+");
302  if( splitLine.length > splitNum ){
303  try {
304  Integer pid = Integer.valueOf(splitLine[splitNum]);
305  if(pid > 0 ){
306  ret.add(pid);
307  }
308  } catch (NumberFormatException ex){
309  ex.printStackTrace();
310  }
311  }
312  }
313  }
314  } catch (Exception e) {
315  e.printStackTrace();
316  }
317  return ret;
318  }
319 
320  public void restart(IProgressMonitor monitor){
321  if(serverManager_ != null){
322  for( ProcessInfo i:serverManager_.getServerInfo()){
323  AProcess server = get(i.id);
324  if( server.isRunning()){
325  server.stop();
326  }
327  unregister(i.id);
328  monitor.worked(1);
329  }
330 
331 
332 
333  ProcessInfo pi = serverManager_.getNameServerInfo();
334 
335  AProcess nameServer = get(serverManager_.getNameServerInfo().id);
336  if(nameServer != null){
337  if(nameServer.isRunning())
338  nameServer.stop();
339  unregister(serverManager_.getNameServerInfo().id);
340  }
341  monitor.worked(1);
342  setProcessList(monitor);
343  }
344  }
345 
346  public static class ProcessInfo implements Cloneable{
347  public String id = null;
348  public List<String> com = new ArrayList<String>();
349  public List<String> env = new ArrayList<String>();
350  public String dir = null;
351  public int waitCount = -1;
352  public boolean isCorbaServer = false;
353  public boolean hasShutdown = false;
354  public boolean doKillall = false;
355  public boolean autoStart = true;
356  public boolean autoStop = true;
357  public String args = "";
358  public boolean useORB = false;
359  public int editComIndex = 0; // for ServerManagerPanel
360 
361  public void print() {
362  GrxDebugUtil.println("\nID: " + id); //$NON-NLS-1$
363  for (int i = 0; i < com.size(); i++) {
364  GrxDebugUtil.println("COM" + i + ": " + com.get(i)); //$NON-NLS-1$ //$NON-NLS-2$
365  }
366  if (env.size() > 0) {
367  for (int i = 0; i < env.size(); i++)
368  GrxDebugUtil.println("ENV" + i + ": " + env.get(i)); //$NON-NLS-1$ //$NON-NLS-2$
369  } else {
370  GrxDebugUtil.println("ENV: use parent process environment"); //$NON-NLS-1$
371  }
372  GrxDebugUtil.println("DIR: " + dir); //$NON-NLS-1$
373  GrxDebugUtil.println("ARGS: " + args); //$NON-NLS-1$
374  }
375 
377  ProcessInfo ret = clone();
378 
379  for(int i = 0; i < com.size(); ++i){
380  ret.com.set(i, GrxXmlUtil.expandEnvVal( com.get(i) ));
381  }
382  ret.dir = GrxXmlUtil.expandEnvVal(dir);
383  ret.args = GrxXmlUtil.expandEnvVal(args);
384 
385  return ret;
386  }
387 
388  protected ProcessInfo clone(){
389  ProcessInfo ret = null;
390  try{
391  ret = (ProcessInfo)super.clone();
392  ret.args = new String(args);
393  ret.dir = new String(dir);
394  ret.com = new ArrayList<String>();
395  for(String i : com){
396  ret.com.add(new String(i));
397  }
398  ret.env = new ArrayList<String>();
399  for(String i : env){
400  ret.com.add(new String(i));
401  }
402  }catch(CloneNotSupportedException ex){
403  ex.printStackTrace();
404  }
405  return ret;
406  }
407  }
408 
409  public void createThread() {
410  if( thread_ == null ){
411  thread_ = new Thread() {
412  public void run() {
413  while (!isEnd_) {
414  updateIO();
415  }
416  }
417  };
418  thread_.start();
419  } else {
420  startType();
421  }
422  }
423 
424  private void updateIO() {
425  for (int i = 0; i < size(); i++) {
426  AProcess p = process_.get(i);
427  if (p == null || p.expecting_) {
428  continue;
429  }
430  StringBuffer sb = p.readLines();
431  if (sb == null || sb.length() == 0) {
432  continue;
433  }
434  String newLine = sb.toString();
435  if (outputBuffer_.length() > 50000) {
436  outputBuffer_.delete(0, newLine.length());
437  }
438  outputBuffer_.append(newLine);
439 
440  //排他処理
441  isType_.lock();
442  if( isType_.get() ){
443  isType_.unlock();
444  } else {
445  //GrxProcessManagerViewが無いときはoutputBuffer_に出力文字列を貯めるだけ
446  isType_.unlock();
447  continue;
448  }
449 
450  if (p.showOutput_) {
451  lineQueue.offer(newLine);
452  }
453  }
454  // SWTEDT(イベントディスパッチスレッド)外からの呼び出しなので、SWTEDTに通知してやってもらう
455  Display display = Display.getDefault();
456  if (display != null && !display.isDisposed()) {
457  display.asyncExec(new Runnable() {
458  public void run() {
459  String newLine = null;
460  while ((newLine = lineQueue.poll()) != null) {
461  notifyObservers("append", newLine);
462  notifyObservers("setTopIndex");
463  }
464  }
465  });
466  }
467  try {
468  Thread.sleep(10);
469  } catch (InterruptedException e) {
470  e.printStackTrace();
471  }
472  }
473 
474  public void clearBuffer(){
475  lineQueue.clear();
476  }
477 
478  public StringBuffer getOutputBuffer(){
479  return outputBuffer_;
480  }
481 
482  public void setOutputBuffer(StringBuffer sb){
483  outputBuffer_ = sb;
484  }
485 
486  public void stopType() {
487  isType_.lock();
488  isType_.set(false);
489  isType_.unlock();
490  }
491 
492  public void startType() {
493  isType_.lock();
494  isType_.set(true);
495  isType_.unlock();
496  }
497 
498  public void stopThread() {
499  isEnd_ = true;
500  try {
501  if(thread_!=null)
502  thread_.join();
503  } catch (InterruptedException ex) {
504  ex.printStackTrace();
505  }
506  }
507 
508  public class AProcess {
509  // configs
510  public ProcessInfo pi_ = null;
511  private Process process_ = null;
512  private StringBuffer com_ = null;
513  private String[] env_ = null;
514  private File dir_ = null;
515  private boolean showOutput_ = true;
516 
517  // variables
518  private boolean expecting_ = false;
519  private InputStream is_ = null;
520  private BufferedReader br_ = null;
521  private InputStream es_ = null;
522  private BufferedReader bre_ = null;
523  private PrintStream ps_ = null;
524  private StringBuffer buf_ = null;
525 
526  public AProcess(ProcessInfo pi) {
527  pi_ = pi;
528  updateCom(0);
529  if (pi_.env.size() > 0) {
530  env_ = new String[pi_.env.size()];
531  for (int i = 0; i < pi_.env.size(); i++)
532  env_[i] = pi_.env.get(i);
533  }
534 
535  try {
536  dir_ = new File( pi_.dir );
537  } catch (Exception e) {
538  dir_ = null;
539  }
540 
541  buf_ = new StringBuffer();
542  }
543 
544  public void setCom(String com){
545  com_ = new StringBuffer(com);
546  }
547 
548  public void updateCom(int i){
549  com_ = new StringBuffer();
550  if (pi_.com.size() > i) {
551  com_.append(pi_.com.get(i)); //$NON-NLS-1$
552  if(pi_.args!=null && !pi_.args.equals(""))
553  com_.append(" "+pi_.args);
554  }
555  }
556 
557  public boolean start(String opt){
558  for(int i=0; i<pi_.com.size(); i++){
559  updateCom(i);
560  if(start0(opt)){
561  Thread thread = new Thread() {
562  public void run() {
563  try {
564  process_.waitFor();
565  Display display = Display.getDefault();
566  if (display != null && !display.isDisposed()) {
567  display.asyncExec(new Runnable() {
568  public void run() {
569  if (showOutput_){
570  notifyObservers("append", "[" + pi_.id + ":O] " + "Process End\n");
571  notifyObservers("setTopIndex");
572  }
573  serverManager_.notifyObservers("ProcessEnd", pi_.id);
574  }
575  });
576  }
577  } catch (InterruptedException e) {
578  e.printStackTrace();
579  }
580  }
581  };
582  thread.start();
583  return true;
584  }
585  }
586  return false;
587  }
588 
589  private boolean start0(String opt) {
590  // StatusOut.append("\nStarting "+pi_.id+" ... ");
591  if (isRunning()) {
592  // StatusOut.append("already running.\n");
593  } else {
594  try {
595  if (opt == null) {
596  opt = ""; //$NON-NLS-1$
597  }
598  GrxDebugUtil.println(com_.toString() + " " + opt); //$NON-NLS-1$
599  if(dir_ != null){
600  if(!dir_.exists())
601  dir_ = null;
602  }
603 
604  String[] _com = com_.toString().split(" ");
605  String[] _opt = opt.split(" ");
606  List<String> com = new ArrayList<String>();
607  for(int i=0; i<_com.length; i++)
608  if(_com[i].trim().length()!=0 )
609  com.add(_com[i]);
610  for(int i=0; i<_opt.length; i++)
611  if(_opt[i].trim().length()!=0 )
612  com.add(_opt[i]);
613  ProcessBuilder pb = new ProcessBuilder(com);
614  if(dir_ == null && new File(com.get(0)).isAbsolute())
615  dir_ = new File(com.get(0)).getParentFile();
616  pb.directory( dir_ );
617  Map<String, String> env = pb.environment();
618  if(env_!=null)
619  for(int i=0; i<env_.length; i++){
620  String[] arg = env_[i].split("=");
621  if(arg.length==2)
622  env.put(arg[0].trim(), arg[1].trim());
623  }
624  Set<String> keySet = env.keySet();
625  String pathKey = null;
626  for (String key : keySet) {
627  if (key.equalsIgnoreCase("Path")) {
628  pathKey = key;
629  }
630  }
631  String path = env.get(pathKey);
632  env.put(pathKey, Activator.getDefault().getPreferenceStore().getString("SERVER_DIR")+File.pathSeparator+path );
633  process_ = pb.start();
634 
635  is_ = process_.getInputStream();
636  br_ = new BufferedReader(new InputStreamReader(is_));
637  es_ = process_.getErrorStream();
638  bre_ = new BufferedReader(new InputStreamReader(es_));
639  ps_ = new PrintStream(process_.getOutputStream());
640 
641  if (pi_.waitCount > 0) {
642  Thread.sleep(pi_.waitCount);
643  }
644  GrxDebugUtil.println("start:OK(" + pi_.id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
645  return true;
646  } catch (Exception e) {
647  process_ = null;
648  //GrxDebugUtil.printErr("start:NG(" + pi_.id + ")", e); //$NON-NLS-1$ //$NON-NLS-2$
649  return false;
650  }
651  }
652  return true;
653  }
654 
655  public boolean stop() {
656  GrxDebugUtil.println("[PMView] stop:stopping " + pi_.id); //$NON-NLS-1$
657  // StatusOut.append("\nStopping "+pi_.id+" ... ");
658  if (isRunning()) {
659  if (pi_.hasShutdown) {
660  return shutdown();
661  }
662  try {
663  if (pi_.doKillall) {
664  String com0 = (pi_.com.get(0));
665  String path = com0.split(" ")[0]; //$NON-NLS-1$
666  String name = new File(path).getName();
667  killall(name);
668  } else {
669  process_.destroy();
670  process_.waitFor();
671  }
672  if (!isRunning()) {
673  process_ = null;
674  // StatusOut.append("OK\n");
675  GrxDebugUtil.println("stop:OK(" + pi_.id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
676  if (pi_.id.equals(nameServerInfo_.id)) { //$NON-NLS-1$
678  }
679  return true;
680  }
681  // StatusOut.append("NG\n");
682  GrxDebugUtil.println("stop:NG(" + pi_.id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
683  return false;
684  } catch (Exception e) {
685  // StatusOut.append("NG\n");
686  GrxDebugUtil.printErr("stop:NG(" + pi_.id + ")", e); //$NON-NLS-1$ //$NON-NLS-2$
687  }
688  } else {
689  // StatusOut.append("not running.\n");
690  GrxDebugUtil.println("stop:" + pi_.id + " is not running."); //$NON-NLS-1$ //$NON-NLS-2$
691  return true;
692  }
693  return false;
694  }
695 
696  private boolean shutdown() {
697  try {
698  // StatusOut.append("\nShutting down "+pi_.id+" ... ");
699  org.omg.CORBA.Object obj = GrxCorbaUtil.getReference(pi_.id);
700  ServerObject serverObj = ServerObjectHelper.narrow(obj);
701  serverObj.shutdown();
702  // StatusOut.append("OK\n");
703  GrxDebugUtil.println("shutdown:OK(" + pi_.id + ")"); //$NON-NLS-1$ //$NON-NLS-2$
704  return true;
705  } catch (Exception e) {
706  // StatusOut.append("NG\n");
707  GrxDebugUtil.printErr("shutdown:NG(" + pi_.id + ")", e); //$NON-NLS-1$ //$NON-NLS-2$
708  } finally {
709  process_.destroy();
710  process_ = null;
711  }
712  return false;
713  }
714 
715  private void closeReader() {
716  try {
717  br_.close();
718  is_.close();
719  bre_.close();
720  es_.close();
721  } catch (IOException e) {
722  GrxDebugUtil.printErr("ProcessManager.closeReader:" + pi_.id + " couldn't close input stream", e); //$NON-NLS-1$ //$NON-NLS-2$
723  }
724  }
725 
726  public boolean isRunning() {
727  try {
728  process_.exitValue();
729  return false;
730  } catch (IllegalThreadStateException e) {
731  return true;
732  } catch (Exception e) {
733  return false;
734  }
735  }
736 
737  private boolean isOpenHRPObject() {
738  return pi_.hasShutdown;
739  }
740 
741  private String expect(String key) {
742  String[] k = { key };
743  return expect(k);
744  }
745 
746  private String expect(String[] key) {
747  expecting_ = true;
748  String str = checkKey(buf_, key);
749  while (isRunning()) {
750  if (str != null) {
751  expecting_ = false;
752  return str;
753  }
754  str = checkKey(readLines(), key);
755  try {
756  Thread.sleep(10);
757  } catch (Exception e1) {}
758  }
759  str = checkKey(readLines(), key);
760  expecting_ = false;
761  return str;
762  }
763 
764  private String checkKey(StringBuffer str, String[] key) {
765  if (str != null) {
766  for (int i = 0; i < key.length; i++) {
767  if (str.indexOf(key[i]) != -1) {
768  return key[i];
769  }
770  }
771  }
772  return null;
773  }
774 
775  private StringBuffer readLine(BufferedReader br) {
776  if (br == null)
777  return null;
778 
779  StringBuffer ret = new StringBuffer();
780  try {
781  while (br.ready()) {
782  char c = (char) br.read();
783  ret.append(c);
784  if (c == '\n')
785  break;
786  }
787  } catch (Exception e) {
788  GrxDebugUtil.printErr("ProcessManager.readLine:(" + pi_.id + ")", e); //$NON-NLS-1$ //$NON-NLS-2$
789  }
790  if (ret.length() == 0) {
791  return null;
792  }
793  return ret;
794  }
795 
796  private StringBuffer readLines() {
797  if (isRunning() || expecting_) {
798  StringBuffer buf = new StringBuffer();
799  for (int i = 0; i < 100; i++) {
800  StringBuffer line1 = readLine(br_);
801  StringBuffer line2 = readLine(bre_);
802  if (line1 != null) {
803  buf.append("[" + pi_.id + ":O] " + line1); //$NON-NLS-1$ //$NON-NLS-2$
804  } else if (line2 == null) {
805  break;
806  }
807  if (line2 != null) {
808  buf.append("[" + pi_.id + ":E] " + line2); //$NON-NLS-1$ //$NON-NLS-2$
809  }
810  }
811 
812  buf_.append(buf);
813  return buf;
814  }
815  return null;
816  }
817 
818  private String readBuffer() {
819  String ret = buf_.toString();
820  clearBuffer();
821  return ret;
822  }
823 
824  private void clearBuffer() {
825  buf_.delete(0, buf_.toString().length());
826  }
827 
828  private void println(String line) {
829  if (ps_ != null) {
830  ps_.println(line + "\n"); //$NON-NLS-1$
831  ps_.flush();
832  }
833  }
834 
835  private void waitFor() {
836  try {
837  process_.waitFor();
838  } catch (InterruptedException e) {
839  e.printStackTrace();
840  }
841  }
842 
843  private org.omg.CORBA.Object getReference() {
844  return GrxCorbaUtil.getReference(pi_.id);
845  }
846 
847  public boolean showOutput(){
848  return showOutput_;
849  }
850 
851  public void setShowOutput(boolean b){
852  showOutput_ = b;
853  }
854  }
855 }
int c
Definition: autoplay.py:16
void setProcessList(IProgressMonitor monitor)
#define null
our own NULL pointer
Definition: IceTypes.h:57
static void deleteNameServerLog(String logPath)
omniName サーバのログファイル削除
Definition: FileUtil.java:77
png_uint_32 size
Definition: png.h:1521
png_infop png_charpp name
Definition: png.h:2382
ConcurrentLinkedQueue< String > lineQueue
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
png_bytep png_bytep png_size_t length
Definition: png.h:1541
png_uint_32 i
Definition: png.h:2735
ProcessInfo getNameServerInfo()
NameServerのProcessInfo取得
long b
Definition: jpegint.h:371
GrxProcessManager(String name, GrxPluginManager manager)
def run(tree, args)
static String expandEnvVal(String str)
png_bytep buf
Definition: png.h:2729
path
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
String checkKey(StringBuffer str, String[] key)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
Vector< ProcessInfo > getServerInfo()
vecServerInfoの取得
void setProcessList(GrxServerManager serverManager)
org
char * arg
Definition: cdjpeg.h:136
List< Integer > getPID(String processName)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22