Example #1
0
 private void closeBundleManagers() {
   for (BundleManager bundleManager : bundleManagers()) {
     if (!bundleManager.isClosed()) {
       disbandBundleManager(bundleManager);
     }
   }
 }
 private BundleManager createBundleManager() {
   String path = getClass().getResource(SCRIPTS_JS).getPath();
   BundleManager bundleManager = new BundleManager();
   Bundle bundle = new Bundle(SCRIPTS_JS);
   bundle.addChildNode(new Fragment(new File(path)));
   bundleManager.addBundle(bundle);
   return bundleManager;
 }
Example #3
0
 private void disbandModuleSpecification(ModuleSpecification moduleSpecification) {
   if (moduleSpecification != null) {
     BundleManager bundleManager = bundleManager(moduleSpecification);
     if (bundleManager != null && !bundleManager.isClosed()) {
       disbandModuleSpecification(bundleManager, moduleSpecification);
     }
   }
 }
 @Override
 public void start(StartContext context) throws StartException {
   super.start(context);
   // Cleanup the storage area
   BundleManager bundleManager = injectedBundleManager.getValue();
   String storageClean = (String) bundleManager.getProperty(Constants.FRAMEWORK_STORAGE_CLEAN);
   if (firstInit == true && Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT.equals(storageClean))
     cleanStorage();
 }
Example #5
0
 private Bundle unmanage(long bundleId) {
   if (isManaged(bundleId)) {
     BundleManager bundleManager = removeBundleManager(bundleId);
     if (bundleManager != null) {
       disbandBundleManager(bundleManager);
       bundleManager.close();
     }
     return bundleManager.getBundle();
   }
   return null;
 }
 /**
  * Decorates the original bundle manager with a version for development.
  *
  * @return a new bundle manager for development, not null
  */
 public BundleManager getDevBundleManager() {
   BundleManager devBundleManager = new BundleManager();
   Set<String> bundleNames = _bundleManager.getBundleIds();
   for (String bundleId : bundleNames) {
     Bundle bundle = _bundleManager.getBundle(bundleId);
     List<Fragment> allFragments = bundle.getAllFragments();
     if (allFragments.size() > LEVEL2_SIZE) {
       throw new IllegalStateException(
           "DevBundleBuilder can only support " + LEVEL2_SIZE + " maximum fragments");
     }
     buildVirtualBundles(devBundleManager, bundleId, allFragments);
   }
   return devBundleManager;
 }
 private File getStorageArea() {
   if (storageArea == null) {
     BundleManager bundleManager = injectedBundleManager.getValue();
     String dirName = (String) bundleManager.getProperty(Constants.FRAMEWORK_STORAGE);
     if (dirName == null) {
       try {
         File storageDir = new File("./osgi-store");
         dirName = storageDir.getCanonicalPath();
       } catch (IOException ex) {
         log.errorf(ex, "Cannot create storage area");
         throw new IllegalStateException("Cannot create storage area");
       }
     }
     storageArea = new File(dirName).getAbsoluteFile();
   }
   return storageArea;
 }
Example #8
0
 private void disbandModuleSpecification(
     BundleManager bundleManager, ModuleSpecification moduleSpecification) {
   try {
     bundleManager.disband(moduleSpecification);
   } finally {
     serviceStatus(moduleSpecification).becameUnhosted();
   }
 }
 private Module findInUnresolvedModules(
     String resName, List<XPackageRequirement> matchingPatterns) {
   log.tracef("Attempt to find path dynamically in unresolved modules ...");
   for (AbstractBundleState bundleState : bundleManager.getBundles()) {
     if (bundleState.getState() == Bundle.INSTALLED) {
       bundleState.ensureResolved(false);
     }
   }
   return findInResolvedModules(resName, matchingPatterns);
 }
Example #10
0
 private void launch(BundleManager bundleManager, ModuleSpecification moduleSpecification) {
   try {
     ObjectManager objectManager = bundleManager.launch(moduleSpecification);
     serviceStatus(moduleSpecification).nowHostedBy(bundleManager);
     log.info(this + " launched " + moduleSpecification + " -> " + objectManager);
   } catch (RuntimeException e) {
     throw new ModuleSystemException(
         this + " failed to launch " + moduleSpecification + " from " + bundleManager, e);
   }
 }
Example #11
0
 private void launch(ModuleSpecification moduleSpecification) {
   BundleManager bundleManager = bundleManager(moduleSpecification);
   if (bundleManager == null) {
     log.info(
         this
             + " received "
             + moduleSpecification
             + ", no object manager factory for that type yet");
   } else if (bundleManager.isClosed()) {
     log.info(
         this
             + " received "
             + moduleSpecification
             + ", object manager factory closed: "
             + bundleManager);
   } else {
     launch(bundleManager, moduleSpecification);
   }
 }
Example #12
0
 private void disbandBundleManager(BundleManager bundleManager) {
   for (String type : bundleManager) {
     for (ServiceStatus serviceStatus : serviceStatii(type)) {
       if (serviceStatus != null && serviceStatus.isHosted()) {
         disbandModuleSpecification(bundleManager, serviceStatus.getModuleSpecification());
       }
     }
   }
   bundleManager.close();
 }
Example #13
0
 private void considerTracking(Bundle bundle) {
   BundleManager existing = bundleManagers.get(bundle.getBundleId());
   if (existing == null) {
     BundleManager bundleManager = BundleManager.manage(bundle, asynch, queuer);
     if (bundleManager != null) {
       storeBundleManager(bundle.getBundleId(), bundleManager);
       launchUnhostedModuleSpecifications(bundleManager);
       log.info(this + " tracks bundle " + bundle + ": " + bundleManager);
     }
   } else {
     log.info(this + " already tracking " + bundle + ": " + existing);
   }
 }
 private Module findInResolvedModules(String resName, List<XPackageRequirement> matchingPatterns) {
   log.tracef("Attempt to find path dynamically in resolved modules ...");
   for (XPackageRequirement pkgreq : matchingPatterns) {
     for (AbstractBundleState bundleState :
         bundleManager.getBundles(Bundle.RESOLVED | Bundle.ACTIVE)) {
       if (bundleState.isResolved() && !bundleState.isFragment()) {
         ModuleIdentifier identifier = bundleState.getModuleIdentifier();
         Module candidate = moduleManager.getModule(identifier);
         if (isValidCandidate(resName, pkgreq, candidate)) return candidate;
       }
     }
   }
   return null;
 }
 private void buildLevelOneBundles(
     BundleManager bundleManager, String bundleId, List<Fragment> fragments) {
   Map<Integer, List<Fragment>> fragmentMap = split(fragments);
   Bundle rootNode = new Bundle(bundleId);
   for (Entry<Integer, List<Fragment>> entry : fragmentMap.entrySet()) {
     String bundleName = buildBundleName(bundleId, String.valueOf(entry.getKey()), null);
     Bundle bundle = new Bundle(bundleName);
     List<Fragment> fragmentList = entry.getValue();
     for (Fragment fragment : fragmentList) {
       bundle.addChildNode(fragment);
     }
     rootNode.addChildNode(bundle);
   }
   bundleManager.addBundle(rootNode);
 }
 private void buildVirtualBundles(
     BundleManager bundleManager, String bundleId, List<Fragment> fragments) {
   long fragmentSize = fragments.size();
   if (fragmentSize <= MAX_IMPORTS) {
     Bundle rootNode = new Bundle(bundleId);
     rootNode.getChildNodes().addAll(fragments);
     bundleManager.addBundle(rootNode);
   }
   if (fragmentSize > MAX_IMPORTS && fragmentSize <= LEVEL1_SIZE) {
     buildLevelOneBundles(bundleManager, bundleId, fragments);
   }
   if (fragmentSize > LEVEL1_SIZE && fragmentSize <= LEVEL2_SIZE) {
     buildLevelTwoBundles(bundleManager, bundleId, fragments);
   }
 }
  public void test() throws Exception {
    Bundle bundle = _bundleManager.getBundle(SCRIPTS_JS);
    List<Fragment> allFragment = bundle.getAllFragment();
    assertNotNull(allFragment);
    assertEquals(1, allFragment.size());

    Fragment fragment = allFragment.get(0);
    fragment.getFile();
    String uncompressed = FileUtils.readFileToString(fragment.getFile());
    assertNotNull(uncompressed);
    s_logger.debug("uncompressed length {}", uncompressed.length());

    String compressed = _compressor.getBundle(SCRIPTS_JS);
    assertNotNull(compressed);
    s_logger.debug("compressed length {}", compressed.length());

    assertTrue(uncompressed.length() > compressed.length());
  }
 private void buildLevelTwoBundles(
     BundleManager bundleManager, String bundleId, List<Fragment> fragments) {
   Map<Integer, List<Fragment>> parentFragmentMap = split(fragments);
   Bundle rootNode = new Bundle(bundleId);
   for (Entry<Integer, List<Fragment>> parentEntry : parentFragmentMap.entrySet()) {
     String parentId = String.valueOf(parentEntry.getKey());
     String parentName = buildBundleName(bundleId, parentId, null);
     Bundle parentBundle = new Bundle(parentName);
     Map<Integer, List<Fragment>> childFragmentMap = split(parentEntry.getValue());
     for (Entry<Integer, List<Fragment>> childEntry : childFragmentMap.entrySet()) {
       String childName = buildBundleName(bundleId, parentId, String.valueOf(childEntry.getKey()));
       Bundle childBundle = new Bundle(childName);
       for (Fragment fragment : childEntry.getValue()) {
         childBundle.addChildNode(fragment);
       }
       parentBundle.addChildNode(childBundle);
     }
     rootNode.addChildNode(parentBundle);
   }
   bundleManager.addBundle(rootNode);
 }
Example #19
0
  /** Creates a chunk map. */
  public static ArrayList<String> getMap(SagaPlayer sagaPlayer, Location location) {

    ArrayList<String> map = new ArrayList<String>();

    int halfHeight = 14 / 2;
    int halfWidth = 24 / 2;

    double inDegrees = location.getYaw();

    Chunk locationChunk = location.getWorld().getChunkAt(location);
    SagaChunk locationSagaChunk = sagaPlayer.getSagaChunk();

    int topLeftX = locationChunk.getX() - halfWidth;
    int topLeftZ = locationChunk.getZ() + halfHeight;

    int width = halfHeight * 2 + 1;
    int height = halfWidth * 2 + 1;

    ChatColor prevColor = null;
    ChatColor color = ChatColor.GRAY;

    // Row:
    for (int dz = -width + 1; dz <= 0; dz++) {
      prevColor = null;
      color = null;

      // Column:
      StringBuffer row = new StringBuffer();
      for (int dx = 0; dx < height; dx++) {

        SagaChunk sagaChunk =
            BundleManager.manager()
                .getSagaChunk(location.getWorld().getName(), topLeftX + dx, topLeftZ + dz);

        String symbol = "?";

        // Claimed:
        if (sagaChunk != null) {

          // Building:
          if (sagaChunk.getBuilding() != null) {
            symbol = BUILDING.replace("B", sagaChunk.getBuilding().getMapChar());
            color = ChatColor.DARK_PURPLE;
          }

          // Border:
          else if (sagaChunk.isBorder()) {
            symbol = BORDER;
            color = ChatColor.GOLD;
          }

          // Claimed:
          else {
            symbol = CLAIMED;
            color = ChatColor.YELLOW;
          }

        }

        // Not claimed:
        else {

          symbol = WILDERNESS;

          Biome biome =
              location.getWorld().getBiome((topLeftX + dx) * 16 + 8, (topLeftZ + dz) * 16 + 8);
          color = BIOME_COLOURS.get(biome);
          if (color == null) color = ChatColor.GRAY;
        }

        // Player location:
        if (dx == halfWidth && dz == -halfHeight) {
          color = ChatColor.DARK_RED;
          symbol = YOUAREHERE;
        }

        // Append new colour:
        if (prevColor != color) {
          row.append(color);
          prevColor = color;
        }

        // Append symbol:
        row.append(symbol);
      }

      map.add(row.toString());
    }

    // Get the compass:
    ArrayList<String> asciiCompass =
        AsciiCompass.getAsciiCompass(inDegrees, ChatColor.RED, ChatColor.GOLD);

    // Add the compass:
    map.set(0, map.get(0) + " " + asciiCompass.get(0));
    map.set(1, map.get(1) + " " + asciiCompass.get(1));
    map.set(2, map.get(2) + " " + asciiCompass.get(2));

    // Add name:
    char[] locationName = null;

    if (locationSagaChunk != null) {
      locationName = locationSagaChunk.getChunkBundle().getName().toUpperCase().toCharArray();
    } else {
      locationName = "WILDERNESS".toCharArray();
    }

    for (int i = 0; i + 4 < map.size() && i < locationName.length; i++) {
      map.set(i + 4, map.get(i + 4) + "   " + ChatColor.GOLD + locationName[i]);
    }

    return map;
  }
 public boolean isValid(Bundle bundle) {
   return BundleManager.assertContains(
       bundle, new String[] {"receiver", "phone_number", "request_id", "user_id"});
 }