/**
  * Test method for {@link edu.ncsu.csc216.androtech.model.management.ServiceManager#printDroids()}
  * .
  */
 @Test
 public void testPrintDroids() {
   serviceManager = new ServiceManager();
   boolean thrown = true;
   try {
     scanner = new Scanner(new File("oneDevice.txt"));
     serviceManager = new ServiceManager(scanner);
     assertEquals(
         serviceManager
             .printDroids()
             .equals(
                 "05V: UNASSIGNED\n03V: UNASSIGNED\n02E: UNASSIGNED\n01C: UNASSIGNED\n04C: UNASSIGNED"),
         true);
     assertEquals(
         serviceManager.printWaitList("").equals("V Gold      0987-N-817 Fath Hoth"), true);
     serviceManager.assignDroids();
     assertEquals(serviceManager.printWaitList("").equals(""), true);
     assertEquals(
         serviceManager
             .printDroids()
             .equals(
                 "05V: 0987-N-817 Fath Hoth\n03V: UNASSIGNED\n02E: UNASSIGNED\n01C: UNASSIGNED\n04C: UNASSIGNED"),
         true);
   } catch (FileNotFoundException e) {
     thrown = false;
   }
   assertTrue(thrown);
 }
 @Override
 public void onReceive(Context context, Intent intent) {
   // 判断用户是否勾选了开机自启
   Toast.makeText(context, "推送已自动开启", 1).show();
   SharedPreferences pref =
       context.getSharedPreferences(Constants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
   if (pref.getBoolean(Constants.SETTINGS_AUTO_START, true)) {
     ServiceManager serviceManager = new ServiceManager(context);
     serviceManager.setNotificationIcon(R.drawable.notification);
     serviceManager.startService();
   }
 }
 /**
  * Test method for {@link
  * edu.ncsu.csc216.androtech.model.management.ServiceManager#putOnWaitingList(edu.ncsu.csc216.androtech.model.devices.Prioritizable)}
  * .
  */
 @Test
 public void testPutOnWaitingListPrioritizable() {
   Prioritizable p1 = vRDevice1;
   Prioritizable p2 = comDevice1;
   serviceManager = new ServiceManager();
   serviceManager.putOnWaitingList(p1);
   serviceManager.putOnWaitingList(p2);
   assertEquals(
       serviceManager
           .printWaitList("")
           .equals("V Gold      0987-N-817 Fath Hoth\nC Gold      0987-N-817 Fath Hoth"),
       true);
 }
 /**
  * Test method for {@link
  * edu.ncsu.csc216.androtech.model.management.ServiceManager#remove(java.lang.String, int)} .
  */
 @Test
 public void testRemove() {
   boolean thrown = true;
   try {
     scanner = new Scanner(new File("oneDevice.txt"));
     serviceManager = new ServiceManager(scanner);
     assertEquals(serviceManager.printWaitList(""), "V Gold      0987-N-817 Fath Hoth");
     serviceManager.remove("", 0);
     assertTrue(serviceManager.printWaitList("").equals(""));
   } catch (FileNotFoundException e) {
     thrown = false;
   }
   assertTrue(thrown);
 }
 @Override
 public ConsumerStatus getStatus() {
   if (disposed) {
     return status;
   }
   return (status = manager.getStatus(uuid));
 }
Example #6
0
 @SuppressWarnings("rawtypes")
 @Override
 public void notifyMobsimAfterSimStep(MobsimAfterSimStepEvent e) {
   if (trackIteration) {
     services.addAll(serviceManager.getFinishedServices());
   }
 }
 @Override
 public Collection<JMXProgressListener> getListeners(Class<? extends JMXProgressListener> clazz) {
   if (disposed) {
     return listeners;
   }
   return (listeners = manager.getListeners(uuid, clazz));
 }
  public static Settings getInstance(Project project) {
    Settings settings = ServiceManager.getService(project, Settings.class);

    settings.project = project;

    return settings;
  }
 @Override
 public void dispose() throws Exception {
   if (!disposed) {
     manager.disposeConsumer(uuid);
     disposed = true;
   }
 }
 /**
  * Test method for {@link edu.ncsu.csc216.androtech.model.management.ServiceManager#addNewDroid()}
  * .
  */
 @Test
 public void testAddNewDroid() {
   serviceManager = new ServiceManager();
   assertTrue(
       serviceManager
           .printDroids()
           .equals(
               "05V: UNASSIGNED\n03V: UNASSIGNED\n02E: "
                   + "UNASSIGNED\n01C: UNASSIGNED\n04C: UNASSIGNED"));
   serviceManager.addNewDroid();
   assertTrue(
       serviceManager
           .printDroids()
           .equals(
               "05V: UNASSIGNED\n03V: UNASSIGNED\n02E: "
                   + "UNASSIGNED\n01C: UNASSIGNED\n04C: UNASSIGNED\n06C: UNASSIGNED"));
 }
Example #11
0
 // luwenchao fix bug 0002953
 // support /mnt/sdcard and /mnt/sdcardEx for ums
 public static String getTFcardStorageState() {
   try {
     IMountService mountService =
         IMountService.Stub.asInterface(ServiceManager.getService("mount"));
     return mountService.getVolumeState(getTFcardStorageDirectory().toString());
   } catch (Exception rex) {
     return Environment.MEDIA_REMOVED;
   }
 }
  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(LOGTAG, "BootReceiverr.onReceive()...");
    String action = intent.getAction();
    Log.d(LOGTAG, "action=" + action);

    // 启动推送服务
    serviceManager = new ServiceManager(context);
    serviceManager.startService();
  }
Example #13
0
  public static VFS getVFSForProtocol(String protocol) {
    if (protocol.equals("file")) return fileVFS;
    else {
      VFS vfs = (VFS) ServiceManager.getService(SERVICE, protocol);
      if (vfs == null) vfs = (VFS) protocolHash.get(protocol);

      if (vfs != null) return vfs;
      else return urlVFS;
    }
  }
 public ServiceResults testDataRequest(
     ServiceManager sm, ServiceAction action, Map<String, Object> properties, Object... params)
     throws Exception {
   ServiceRequest request = sm.newRequest(action, parameters(params), payload(properties));
   logger.info("Request: " + action + " " + request.toString());
   dumpProperties(properties);
   ServiceResults results = request.execute();
   assertNotNull(results);
   assertNotNull(results.getData());
   dump(results.getData());
   return results;
 }
 private CoasterChannel getChannel(Task task)
     throws InvalidServiceContactException, IllegalSpecException, TaskSubmissionException,
         InvalidSecurityContextException, ChannelException, InterruptedException {
   if (autostart) {
     String provider = getBootHandlerProvider(task);
     url = ServiceManager.getDefault().reserveService(task, provider);
     task.getService(0).setAttribute("coaster-url", url);
   } else {
     url = task.getService(0).getServiceContact().getContact();
   }
   return ChannelManager.getManager().getOrCreateChannel(url, cred, LocalRequestManager.INSTANCE);
 }
 /**
  * 获取指定资源的关联资源集合
  *
  * @param resId 指定资源ID
  * @return
  */
 public List<ResourceObject> getResourceRelations(int resId) {
   List<ResourceObject> list = new ArrayList<ResourceObject>();
   IResourceService is = ServiceManager.getResourceService();
   List<ResourceRelation> l = this.getRelationsByResourceId(resId);
   for (ResourceRelation r : l) {
     if (r.getItemId() == resId) {
       list.add(is.getResourceById(r.getItemId2()));
     } else if (r.getItemId2() == resId) {
       list.add(is.getResourceById(r.getItemId()));
     }
   }
   return list;
 }
Example #17
0
  public static String[] getVFSs() {

    List returnValue = new LinkedList();
    String[] newAPI = ServiceManager.getServiceNames(SERVICE);
    if (newAPI != null) {
      for (int i = 0; i < newAPI.length; i++) {
        returnValue.add(newAPI[i]);
      }
    }
    Enumeration oldAPI = vfsHash.keys();
    while (oldAPI.hasMoreElements()) returnValue.add(oldAPI.nextElement());
    return (String[]) returnValue.toArray(new String[returnValue.size()]);
  }
  public JMXConsumerManager(Map<String, String> configuration, ServiceManager manager)
      throws Exception {
    super();
    if (configuration == null)
      throw new IllegalArgumentException(
          "Unable to build the " + JMXConsumerManager.class + " using a null configuration");

    this.configuration = configuration;

    this.manager = manager;

    this.uuid = manager.createConsumer(configuration);
  }
 /**
  * 生成资源关联关系拓扑图数据
  *
  * @param list 资源关联关系
  * @param def 如果list.size=0, 默认显示的节点
  * @return 拓扑图数据
  */
 private String getResourceRelationXml(
     List<ResourceRelation> list, ResourceRelation def, int resId) {
   Document doc = null;
   try {
     doc = XmlUtil.parseString("<Graph/>");
   } catch (DocumentException e) {
     // 此处不可能发生
     e.printStackTrace();
     return "";
   }
   boolean f = false;
   if (list.size() == 0 && def != null) {
     f = true;
     list.add(def);
   }
   Map<Integer, ResourceObject> m = new HashMap<Integer, ResourceObject>();
   IResourceService is = ServiceManager.getResourceService();
   for (ResourceRelation r : list) {
     ResourceObject ro = is.getResourceById(r.getItemId());
     ResourceObject ro1 = is.getResourceById(r.getItemId2());
     if (ro != null) m.put(ro.getId(), ro);
     if (ro1 != null) m.put(ro1.getId(), ro1);
   }
   for (ResourceObject ro : m.values()) {
     Element el = doc.getRootElement().addElement("Node");
     el.addAttribute("id", String.valueOf(ro.getId()));
     el.addAttribute("name", ro.getName());
     if (resId > 0 && ro.getId() == resId) el.addAttribute("nodeSize", "50");
     else el.addAttribute("nodeSize", "32");
     el.addAttribute("nodeIcon", String.valueOf(ro.getModel().getIcon()));
   }
   for (ResourceRelation r : list) {
     if (f) break;
     Element el = doc.getRootElement().addElement("Edge");
     el.addAttribute("fromID", String.valueOf(r.getItemId()));
     el.addAttribute("toID", String.valueOf(r.getItemId2()));
     RelationDefine rd = getRelationDefineById(r.getRelationId());
     if (rd != null) {
       el.addAttribute("edgeLabel", rd.getName());
       if (rd.getIcon() != null && rd.getIcon().length() > 0)
         el.addAttribute("edgeClass", rd.getIcon());
       if (rd.getColor() != null && rd.getColor().length() > 0)
         el.addAttribute("color", rd.getColor());
     } else {
       el.addAttribute("edgeLabel", "关系未定义");
     }
   }
   return XmlUtil.getXmlString(doc);
 }
 /**
  * 获取某个资源有可能会有关联关系的资源集合.(包含本身) 即取出指定资源所属模型的所有关联模型下的所有资源.
  *
  * @param resId 指定资源ID
  * @return
  */
 public List<ResourceObject> getRelationsWithModelByResId(int resId, int userId) {
   List<ResourceObject> list = new ArrayList<ResourceObject>();
   IResourceService is = ServiceManager.getResourceService();
   ResourceObject r = is.getResourceById(resId);
   Map<String, String> m = new HashMap<String, String>();
   for (ModelRelation mr : getModelRelationsByModelId(r.getModelId())) {
     if (!mr.getModelId().equals(r.getModelId())) m.put(mr.getModelId(), "1");
     if (!mr.getModelId2().equals(r.getModelId())) m.put(mr.getModelId2(), "1");
   }
   for (String modelId : m.keySet()) {
     list.addAll(is.getResourcesByModelId(modelId, userId));
   }
   list.add(r);
   return list;
 }
 public ServiceResults testBatchRequest(
     ServiceManager sm,
     ServiceAction action,
     int expectedCount,
     List<Map<String, Object>> batch,
     Object... params)
     throws Exception {
   ServiceRequest request = sm.newRequest(action, parameters(params), batchPayload(batch));
   logger.info("Request: " + action + " " + request.toString());
   dump("Batch", batch);
   ServiceResults results = request.execute();
   assertNotNull(results);
   assertEquals(expectedCount, results.getEntities().size());
   dumpResults(results);
   return results;
 }
Example #22
0
 private static StorageVolume getPrimaryVolume() {
   if (mPrimaryVolume == null) {
     synchronized (mLock) {
       if (mPrimaryVolume == null) {
         try {
           IMountService mountService =
               IMountService.Stub.asInterface(ServiceManager.getService("mount"));
           Parcelable[] volumes = mountService.getVolumeList();
           mPrimaryVolume = (StorageVolume) volumes[0];
         } catch (Exception e) {
           Log.e(TAG, "couldn't talk to MountService", e);
         }
       }
     }
   }
   return mPrimaryVolume;
 }
 /**
  * Test method for {@link
  * edu.ncsu.csc216.androtech.model.management.ServiceManager#assignDroids()} .
  */
 @Test
 public void testAssignDroids() {
   serviceManager = new ServiceManager();
   serviceManager.putOnWaitingList(vRDevice1);
   serviceManager.putOnWaitingList(comDevice1);
   assertEquals(
       serviceManager.printWaitList(""),
       "V Gold      0987-N-817 Fath Hoth\nC Gold      0987-N-817 Fath Hoth");
   serviceManager.assignDroids();
   assertEquals(serviceManager.printWaitList("").equals(""), true);
   assertEquals(
       serviceManager
           .printDroids()
           .equals(
               "05V: 0987-N-817 Fath Hoth\n03V: UNASSIGNED\n02E:"
                   + " UNASSIGNED\n01C: UNASSIGNED\n04C: 0987-N-817 Fath Hoth"),
       true);
 }
 /**
  * 生成模型关联关系拓扑图数据
  *
  * @return 拓扑图数据
  */
 private String getModelRelationXml(List<ModelRelation> list) {
   Document doc = null;
   try {
     doc = XmlUtil.parseString("<Graph/>");
   } catch (DocumentException e) {
     // 此处不可能发生
     e.printStackTrace();
     return "";
   }
   IModelService ms = ServiceManager.getModelService();
   Map<String, Model> map = new HashMap<String, Model>();
   for (int i = 0; i < list.size(); i++) {
     ModelRelation mr = list.get(i);
     Model m1 = ms.getModelById(mr.getModelId());
     Model m2 = ms.getModelById(mr.getModelId2());
     map.put(m1.getId(), m1);
     map.put(m2.getId(), m2);
   }
   Model[] models = map.values().toArray(new Model[] {});
   for (int i = 0; i < models.length; i++) {
     Model m = models[i];
     Element el = doc.getRootElement().addElement("Node");
     el.addAttribute("id", m.getId());
     el.addAttribute("name", m.getName());
     el.addAttribute("nodeIcon", "" + m.getLargeIcon());
     el.addAttribute("nodeSize", "32");
   }
   for (int i = 0; i < list.size(); i++) {
     ModelRelation mr = list.get(i);
     Element el = doc.getRootElement().addElement("Edge");
     el.addAttribute("fromID", mr.getModelId());
     el.addAttribute("toID", mr.getModelId2());
     el.addAttribute("edgeLabel", getRelationDefineById(mr.getRelationId()).getName());
   }
   return XmlUtil.getXmlString(doc);
 }
 @Override
 public void run(Serializable event) throws Exception {
   if (!disposed) manager.runConsumer(uuid, event);
   else throw new IllegalStateException("Unable to run consumer on a disposed " + this.getClass());
 }
 public static MavenWorkspaceSettingsComponent getInstance(Project project) {
   return ServiceManager.getService(project, MavenWorkspaceSettingsComponent.class);
 }
 public static Kotlin2JvmCompilerArgumentsHolder getInstance(Project project) {
   return ServiceManager.getService(project, Kotlin2JvmCompilerArgumentsHolder.class);
 }
 public static ZkConfigPersistence getInstance(Project project) {
   return ServiceManager.getService(project, ZkConfigPersistence.class);
 }
 public static SpellCheckerSettings getInstance(Project project) {
   return ServiceManager.getService(project, SpellCheckerSettings.class);
 }
 /**
  * Get project instance
  *
  * @param project the context project
  * @return the created instance
  */
 public static AnalyzeDependenciesSettings getInstance(Project project) {
   return ServiceManager.getService(project, AnalyzeDependenciesSettings.class);
 }