Package org.wso2.carbon.bam.util

Examples of org.wso2.carbon.bam.util.BAMCalendar


                    + cacheKey);
        }

        // look up cache
        Object prop = cfgCtx.getPropertyNonReplicable(CachingConstants.CACHE_MANAGER);
        CacheManager cacheManager;
        if (prop != null && prop instanceof CacheManager) {
            cacheManager = (CacheManager) prop;
        } else {
            synchronized (cfgCtx) {
                // check again after taking the lock to make sure no one else did it before us
                prop = cfgCtx.getPropertyNonReplicable(CachingConstants.CACHE_MANAGER);
                if (prop != null && prop instanceof CacheManager) {
                    cacheManager = (CacheManager) prop;

                } else {
                    synLog.traceOrDebug("Creating/recreating the cache object");
                    cacheManager = new CacheManager();
                    cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
                }
            }
        }
View Full Code Here


            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Storing the response message into the cache at scope : " +
                    scope + " with ID : " + cacheKey + " for request hash : " + requestHash);
            }

            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);
            if (cachedObj != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Storing the response for the message with ID : " +
                        synCtx.getMessageID() + " with request hash ID : " +
                        cachedObj.getRequestHash() + " in the cache : " + cacheKey);
                }

                ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                try {
                    MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope()).serialize(outStream);
                    cachedObj.setResponseEnvelope(outStream.toByteArray());
                } catch (XMLStreamException e) {
                    handleException("Unable to set the response to the Cache", e, synCtx);
                }

                /* this is not required yet, can commented this for perf improvements
                   in the future there can be a situation where user sends the request
                   with the response hash (if client side caching is on) in which case
                   we can compare that response hash with the given response hash and
                   respond with not-modified http header */
                // cachedObj.setResponseHash(cache.getGenerator().getDigest(
                //     ((Axis2MessageContext) synCtx).getAxis2MessageContext()));

                if (cachedObj.getTimeout() > 0) {
                    cachedObj.setExpireTimeMillis(System.currentTimeMillis() + cachedObj.getTimeout());
                }

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

        if (cacheManager.containsKey(cacheKey, requestHash) &&
            cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx) != null) {

            // get the response from the cache and attach to the context and change the
            // direction of the message
            CachedObject cachedObj = cacheManager.getResponseForKey(cacheKey, requestHash, cfgCtx);

            if (!cachedObj.isExpired() && cachedObj.getResponseEnvelope() != null) {

                if (synLog.isTraceOrDebugEnabled()) {
                    synLog.traceOrDebug("Cache-hit for message ID : " + synCtx.getMessageID());
                }

                // mark as a response and replace envelope from cache
                synCtx.setResponse(true);
                try {
                    SOAPEnvelope omSOAPEnv = SOAPMessageHelper.buildSOAPEnvelopeFromBytes(
                            cachedObj.getResponseEnvelope());

                    // todo: if there is a WSA messageID in the response, is that need to be unique on each and every resp

                    synCtx.setEnvelope(omSOAPEnv);
                } catch (AxisFault axisFault) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, synCtx);
                } catch (IOException ioe) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, ioe, synCtx);
                } catch (SOAPException soape) {
                    handleException("Error setting response envelope from cache : "
                        + cacheKey, soape, synCtx);
                }

                // take specified action on cache hit
                if (onCacheHitSequence != null) {
                    // if there is an onCacheHit use that for the mediation
                    synLog.traceOrDebug("Delegating message to the onCachingHit "
                            + "Anonymous sequence");
                    onCacheHitSequence.mediate(synCtx);

                } else if (onCacheHitRef != null) {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Delegating message to the onCachingHit " +
                            "sequence : " + onCacheHitRef);
                    }
                    synCtx.getSequence(onCacheHitRef).mediate(synCtx);

                } else {

                    if (synLog.isTraceOrDebugEnabled()) {
                        synLog.traceOrDebug("Request message " + synCtx.getMessageID() +
                            " was served from the cache : " + cacheKey);
                    }
                    // send the response back if there is not onCacheHit is specified
                    synCtx.setTo(null);
                    Axis2Sender.sendBack(synCtx);
                }
                // stop any following mediators from executing
                return false;

            } else {
                // cache exists, but has expired...
                cachedObj.expire();
                cachedObj.setTimeout(timeout);
                synLog.traceOrDebug("Existing cached response has expired. Reset cache element");

                cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//                Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
                Replicator.replicate(cfgCtx);
View Full Code Here

     * @throws ClusteringFault if there is an error in replicating the cfgCtx
     */
    private void storeRequestToCache(ConfigurationContext cfgCtx,
        String requestHash, CacheManager cacheManager) throws ClusteringFault {

        CachedObject cachedObj = new CachedObject();
        cachedObj.setRequestHash(requestHash);
        // this does not set the expiretime but just sets the timeout and the espiretime will
        // be set when the response is availabel
        cachedObj.setTimeout(timeout);
        cacheManager.addResponseWithKey(cacheKey, requestHash, cachedObj, cfgCtx);

        cfgCtx.setProperty(CachingConstants.CACHE_MANAGER, cacheManager);
//        Replicator.replicate(cfgCtx, new String[]{cacheManagerKey});
        Replicator.replicate(cfgCtx);
View Full Code Here

            // do not delete anything if the retention period specified is 0.
            TimeRange retention = BAMPersistenceManager.getPersistenceManager(
                    BAMUtil.getRegistry()).getDataRetentionPeriod();
            if ((retention != null) && (retention.getValue() != 0)) {

                BAMCalendar delLoHour = BAMCalendar.getInstance(start);
                BAMCalendar delHiHour = BAMCalendar.getInstance(end);

                delHiHour.add(retention.getType(), -1 * retention.getValue());
                delLoHour.add(retention.getType(), -1 * retention.getValue());
               
                deleteServerUserData(delLoHour, delHiHour);
            }
            //End TODO
View Full Code Here

    public MeteringSummaryGenerationDSStub getStub(){
        return meteringStub;
    }
   
    public Calendar getLatestSummaryTime(int summaryPeriod, int serverId) throws BAMException{
        BAMCalendar cal = null;

        try {
            SummaryTime[] time;
            switch (summaryPeriod) {
            case BAMCalendar.HOUR_OF_DAY:
                time = meteringStub.getLatestHourlyBandwidthSummaryPeriodId(serverId);
                break;
            case BAMCalendar.DAY_OF_MONTH:
                time = meteringStub.getLatestDailyBandwidthSummaryPeriodId(serverId);
                break;
            case BAMCalendar.MONTH:
                time = meteringStub.getLatestMonthlyBandwidthSummaryPeriodId(serverId);
                break;
            case BAMCalendar.QUATER:
                time = meteringStub.getLatestQuarterlyBandwidthSummaryPeriodId(serverId);
                break;
            case BAMCalendar.YEAR:
                time = meteringStub.getLatestYearlyBandwidthSummaryPeriodId(serverId);
                break;
            default:
                throw new BAMException("Unexpected timeInterval");
            }
           
            if (time != null && time[0] != null) {
                //we are sure that there will be only one record.
                cal = BAMCalendar.getInstance(time[0].getStartTime());
            }else {
                //This is the first time we are running the summary. So, get the minimum time stamp
                //for this server from "server user data" table
                time = meteringStub.getMinimumPeriodId(serverId);
                if (time != null && time[0] != null) {
                    //we are sure that there will be only one record.
                    cal = BAMCalendar.getInstance(time[0].getStartTime());
                }else{
                    //We are running for the first time and there are no records in
                    //"server user data". So, we can start from now
                    cal = BAMCalendar.getInstance();
                }
                //Start with last period so that it will include our intended period
                cal.add(summaryPeriod, -2);
            }
           
        } catch (Exception e) {
            String msg = "Unable to get LatestSummaryTime";
            log.error(msg);
View Full Code Here

        }
        return cal;
    }
   
    public Calendar getLatestRegSummaryTime(int summaryPeriod, int tenantId) throws BAMException{
        BAMCalendar cal = null;

        try {
            SummaryTime[] time;
            switch (summaryPeriod) {
            case BAMCalendar.DAY_OF_MONTH:
                time = meteringStub.getLatestDailyRegistryBandwidthSummaryPeriodId(tenantId);
                break;
            case BAMCalendar.MONTH:
                time = meteringStub.getLatestMonthlyRegistryBandwidthSummaryPeriodId(tenantId);
                break;
            default:
                throw new BAMException("Unexpected timeInterval");
            }
            if (time == null || time[0] == null) {
                //This is the first time we are running the summary. So, start with current - 1 period
                cal = BAMCalendar.getInstance();
                cal.add(summaryPeriod, -2);
            }else{
                //we are sure that there will be only one record.
                cal = BAMCalendar.getInstance(time[0].getStartTime());
            }
        } catch (Exception e) {
View Full Code Here

        BAMServiceSummaryDSClient serviceSummaryDSClient = null;
    try {
      serviceSummaryDSClient = BAMUtil.getBAMServiceSummaryDSClient();
            SummaryStatistic stat = serviceSummaryDSClient.getServiceStatHourlySummary(serviceId, startTime, endTime);

            BAMCalendar prevHourStartTime = BAMCalendar.getInstance(startTime);
            prevHourStartTime.add(BAMCalendar.HOUR_OF_DAY, -24);
            BAMCalendar prevHourEndTime = BAMCalendar.getInstance(endTime);
            prevHourEndTime.add(BAMCalendar.HOUR_OF_DAY, -1);

            SummaryStatistic maxStatThisHour = serviceSummaryDSClient.getServiceMaxCounts(serviceId, startTime, endTime);
            SummaryStatistic maxStatPrevHour = serviceSummaryDSClient.getServiceMaxCounts(serviceId, prevHourStartTime,
                    prevHourEndTime);
View Full Code Here

        BAMServiceSummaryDSClient serviceSummaryDSClient = null;
    try {
      serviceSummaryDSClient = BAMUtil.getBAMServiceSummaryDSClient();
      SummaryStatistic stat = serviceSummaryDSClient.getServerStatHourlySummary(serverId, startTime, endTime);

            BAMCalendar prevHourStartTime = BAMCalendar.getInstance(startTime);
            prevHourStartTime.add(BAMCalendar.HOUR_OF_DAY, -24);
            BAMCalendar prevHourEndTime = BAMCalendar.getInstance(endTime);
            prevHourEndTime.add(BAMCalendar.HOUR_OF_DAY, -1);

            SummaryStatistic maxStatThisHour = serviceSummaryDSClient.getServerMaxCounts(serverId, startTime, endTime);
            SummaryStatistic maxStatPrevHour = serviceSummaryDSClient.getServerMaxCounts(serverId, prevHourStartTime, prevHourEndTime);

            int val;
View Full Code Here

  public QuarterDimension getQuarterDimension(Calendar quater) throws BAMException {
        SummaryDimensionDSClient summaryDimension = null;
    try {
      summaryDimension = BAMUtil.getSummaryDimensionDSClient();

            BAMCalendar bamQuater = BAMCalendar.getInstance(quater);
      YearDimension yd = getYearDimension(quater);
      if (yd == null)
        return null;
      return summaryDimension.getQuarterDimension(bamQuater.get(BAMCalendar.QUATER), yd.getId());
    } catch (Exception e) {
      throw new BAMException("Retrieving quarter dimension failed for timestamp "
          + BAMCalendar.getInstance(quater).getBAMTimestamp(), e);
    } finally {
      if (summaryDimension != null) {
View Full Code Here

TOP

Related Classes of org.wso2.carbon.bam.util.BAMCalendar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.