Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  public void cleanup() {
    long now = System.currentTimeMillis();
    ArrayList<K> keysToDelete = null;

    synchronized (cacheMap) {
      MapIterator itr = cacheMap.mapIterator();

      keysToDelete = new ArrayList<K>((cacheMap.size() / 2) + 1);
      K key = null;
      CachedObject c = null;

      while (itr.hasNext()) {
        key = (K) itr.next();
        c = (CachedObject) itr.getValue();

        if (c != null && (now > ((1000L * timeToLiveInSeconds) + c.lastAccessed))) {
          keysToDelete.add(key);
        }
      }
    }

    for (K key : keysToDelete) {
      synchronized (cacheMap) {
        cacheMap.remove(key);
      }
      Thread.yield();
    }
  }
  private IPentahoUser convertToPentahoUser(User jackrabbitUser) throws RepositoryException {
    if (userCache.containsKey(jackrabbitUser.getID())) {
      return (IPentahoUser) userCache.get(jackrabbitUser.getID());
    }
    IPentahoUser pentahoUser = null;
    Value[] propertyValues = null;

    String description = null;
    try {
      propertyValues = jackrabbitUser.getProperty("description"); // $NON-NLS-1$
      description = propertyValues.length > 0 ? propertyValues[0].getString() : null;
    } catch (Exception ex) {
    }

    Credentials credentials = jackrabbitUser.getCredentials();
    String password = null;
    if (credentials instanceof CryptedSimpleCredentials) {
      password = new String(((CryptedSimpleCredentials) credentials).getPassword());
    }

    pentahoUser =
        new PentahoUser(
            tenantedUserNameUtils.getTenant(jackrabbitUser.getID()),
            tenantedUserNameUtils.getPrincipleName(jackrabbitUser.getID()),
            password,
            description,
            !jackrabbitUser.isDisabled());

    userCache.put(jackrabbitUser.getID(), pentahoUser);
    return pentahoUser;
  }
Ejemplo n.º 3
0
 /** {@inheritDoc} */
 @Override
 public void put(K key, T value) {
   synchronized (cacheMap) {
     if (this.putNullsInCache) {
       cacheMap.put(key, new CachedObject(value));
     } else {
       if (value != null) {
         cacheMap.put(key, new CachedObject(value));
       }
     }
   }
 }
Ejemplo n.º 4
0
 private WebSocketChannelDTO getChannel(int channelId) throws SQLException, DatabaseException {
   if (!channelCache.containsKey(channelId)) {
     WebSocketChannelDTO criteria = new WebSocketChannelDTO();
     criteria.id = channelId;
     List<WebSocketChannelDTO> channels = getChannels(criteria);
     if (channels.size() == 1) {
       channelCache.put(channelId, channels.get(0));
     } else {
       throw new SQLException("Channel '" + channelId + "' not found!");
     }
   }
   return (WebSocketChannelDTO) channelCache.get(channelId);
 }
Ejemplo n.º 5
0
  public void close() {
    lru.clear();
    maxmind.close();

    if (asnLookup != null) {
      asnLookup.close();
    }
  }
Ejemplo n.º 6
0
 public void execute(final RulesData rules, final List<? extends RuleProxy<?, ?>> data)
     throws Exception {
   long timing = System.currentTimeMillis();
   ExecutionSetEntry entry;
   synchronized (entries) {
     entry = (ExecutionSetEntry) entries.get(rules.getUid());
     if (entry == null) {
       entry = ExecutionSetEntry.load(folder, rules.getUid());
       if (entry == null) {
         entry = new ExecutionSetEntry(rules.getUid());
       }
       entries.put(entry.getRulesUid(), entry);
     }
   }
   entry.getSession(rules, folder).execute(data);
   // MiscUtil.logTiming(timing, "executed rules " + rules);
 }
Ejemplo n.º 7
0
  public Map<String, Object> getLocation(String ip)
      throws JsonGenerationException, JsonMappingException, IOException {
    for (String prefix : rfc1918Slash8Prefixes) {
      if (ip.startsWith(prefix)) {
        for (String addrPrefix : rfc1918AddressPrefixes) {
          if (ip.startsWith(addrPrefix)) return RFC1918_GEO;
        }
        break;
      }
    }

    Object val = lru.get(ip);
    if (val != null) return (Map<String, Object>) val;

    Location loc = maxmind.getLocation(ip);
    if (loc == null) {
      lru.put(ip, UNKNOWN_GEO);
      return UNKNOWN_GEO;
    }

    Map<String, Object> rec = new HashMap<String, Object>();
    put(rec, "city", loc.city);
    put(rec, "cc", loc.countryCode);
    put(rec, "country", loc.countryName);
    put(rec, "lat", loc.latitude);
    put(rec, "long", loc.longitude);

    if (asnLookup != null) {
      String org = asnLookup.getOrg(ip);
      if (org != null) {
        Matcher mat = asnumPattern.matcher(org);
        if (mat.matches()) {
          put(rec, "asn", mat.group(1));
          put(rec, "org", mat.group(2));
        } else {
          put(rec, "org", org);
        }
      }
    }

    lru.put(ip, rec);
    return rec;
  }
Ejemplo n.º 8
0
 public void dispose() {
   if (timer != null) {
     timer.cancel();
     timer = null;
   }
   synchronized (entries) {
     entries.clear();
   }
   LOG.info("disposed");
 }
Ejemplo n.º 9
0
  /** {@inheritDoc} */
  @Override
  public T get(K key) {
    synchronized (cacheMap) {
      CachedObject c = (CachedObject) cacheMap.get(key);

      if (c == null) return null;
      else {
        c.lastAccessed = System.currentTimeMillis();
        return c.value;
      }
    }
  }
  public void setPassword(
      Session session, final ITenant theTenant, final String userName, final String password)
      throws NotFoundException, RepositoryException {
    User jackrabbitUser = getJackrabbitUser(theTenant, userName, session);
    if ((jackrabbitUser == null)
        || !TenantUtils.isAccessibleTenant(
            theTenant == null
                ? tenantedUserNameUtils.getTenant(jackrabbitUser.getID())
                : theTenant)) {
      throw new NotFoundException(
          Messages.getInstance()
              .getString("AbstractJcrBackedUserRoleDao.ERROR_0003_USER_NOT_FOUND"));
    }
    jackrabbitUser.changePassword(password);

    /** BISERVER-9906 Clear cache after changing password */
    purgeUserFromCache(userName);
    userCache.remove(jackrabbitUser.getID());
  }
Ejemplo n.º 11
0
 private boolean isWait(JobInProgress job) {
   long bookingTime = job.getJobConf().getLong(BOOKING_TIME, 0);
   String[] dependencyJobs = job.getJobConf().getStrings(BOOKING_DEPENDENCY_JOBID, null);
   boolean bookingTimeFilter = false;
   boolean dependencyJobFilter = false;
   if (bookingTime >= System.currentTimeMillis()) {
     bookingTimeFilter = true;
   }
   if (null != dependencyJobs) {
     for (String dependencyJob : dependencyJobs) {
       JobStatus dependencyJobStatus = (JobStatus) finishJobStatus.get(dependencyJob);
       if (null != dependencyJobStatus
           && dependencyJobStatus.getRunState() != JobStatus.SUCCEEDED) {
         dependencyJobFilter = true;
       }
     }
   }
   if (bookingTimeFilter || dependencyJobFilter) return true;
   else return false;
 }
Ejemplo n.º 12
0
 @Override
 protected void jobNoLongerRunning(JobInProgress job) {
   super.jobNoLongerRunning(job);
   finishJobStatus.put(job.getJobConf().getJobName(), job.getStatus());
 }
Ejemplo n.º 13
0
  /**
   * This method is used for generating HTML file base on given folder, job name and xsl file name.
   *
   * @param tempFolderPath a string
   * @param jobName a string
   * @param htmlFileMap
   * @param xslFileName a string
   */
  public static void generateHTMLFile(
      String tempFolderPath,
      String xslFilePath,
      String xmlFilePath,
      String htmlFilePath,
      Map<String, Object> htmlFileMap) {

    Map<String, Object> nodeHTMLMap = htmlFileMap;
    generateHTMLFile(tempFolderPath, xslFilePath, xmlFilePath, htmlFilePath);

    File originalHtmlFile = new File(htmlFilePath);

    if (!originalHtmlFile.exists()) {
      return;
    }

    BufferedReader mainHTMLReader = null;
    BufferedWriter newMainHTMLWriter = null;
    // BufferedReader externalNodeHTMLReader = null;
    File newMainHTMLFile = null;
    try {

      mainHTMLReader = new BufferedReader(new FileReader(originalHtmlFile));

      newMainHTMLFile = new File(htmlFilePath + "temp"); // $NON-NLS-1$

      newMainHTMLWriter = new BufferedWriter(new FileWriter(newMainHTMLFile));
      String lineStr = ""; // $NON-NLS-1$
      while ((lineStr = mainHTMLReader.readLine()) != null) {
        newMainHTMLWriter.write(lineStr);
        for (String key : htmlFileMap.keySet()) {
          String compareStr =
              "<!--" + key + "ended-->"; // tMap_1ended--> //$NON-NLS-1$ //$NON-NLS-2$
          if (lineStr.indexOf(compareStr) != -1) {

            if (htmlFileMap.get(key) instanceof URL) {
              File externalNodeHTMLFile = new File(((URL) nodeHTMLMap.get(key)).getPath());

              String content =
                  (String) externalNodeFileCache.get(externalNodeHTMLFile.getAbsolutePath());
              if (content == null) {
                content = FileUtils.readFileToString(externalNodeHTMLFile);
                // put file content into cache
                externalNodeFileCache.put(externalNodeHTMLFile.getAbsolutePath(), content);
              }
              newMainHTMLWriter.write(content);
            } else if (htmlFileMap.get(key) instanceof String) {
              newMainHTMLWriter.write((String) htmlFileMap.get(key));
            }
          }
          // htmlFileMap.remove(key);
        }
      }

    } catch (Exception e) {
      ExceptionHandler.process(e);
    } finally {
      try {
        if (mainHTMLReader != null) {
          mainHTMLReader.close();
        }
        if (newMainHTMLWriter != null) {
          newMainHTMLWriter.close();
        }
        // if (externalNodeHTMLReader != null) {
        // externalNodeHTMLReader.close();
        // }
      } catch (IOException e) {
        ExceptionHandler.process(e);
      }

      originalHtmlFile.delete();
      newMainHTMLFile.renameTo(new File(htmlFilePath));
      // System.out.println("isWorked= " + isWorked);

      // copy(htmlFilePath + "temp", htmlFilePath);
      //
      // System.out.println("tempFilePath:" + htmlFilePath + "temp");
      // System.out.println("htmlFilePath:" + htmlFilePath);
    }
  }
Ejemplo n.º 14
0
 public static void clearExternalNodeFileCache() {
   externalNodeFileCache.clear();
 }
Ejemplo n.º 15
0
 /** {@inheritDoc} */
 @Override
 public void delete(K key) {
   synchronized (cacheMap) {
     cacheMap.remove(key);
   }
 }
Ejemplo n.º 16
0
 /** {@inheritDoc} */
 @Override
 public int size() {
   synchronized (cacheMap) {
     return cacheMap.size();
   }
 }