Package org.rioproject.impl.service

Examples of org.rioproject.impl.service.ServiceResource


        }
    }

    @Override
    protected void add(LeasedResource resource) {
        ServiceResource sr = (ServiceResource)resource;
        InstantiatorResource ir = (InstantiatorResource)sr.getResource();
        synchronized(resourceList) {
            Bucket bucket = null;
            for(Bucket b : resourceList) {
                if(b.getLabel().equals(ir.getHostAddress())) {
                    bucket = b;
View Full Code Here


        super.add(resource);
    }

    @Override
    protected void remove(LeasedResource resource) {
        ServiceResource sr = (ServiceResource)resource;
        InstantiatorResource ir = (InstantiatorResource)sr.getResource();
        synchronized(resourceList) {
            for(Bucket b : resourceList) {
                if(b.getLabel().equals(ir.getHostAddress())) {
                    b.remove(sr);
                    break;
View Full Code Here

                Set<Key> keySet = collection.keySet();
                keys = keySet.toArray(new Key[keySet.size()]);
            }
            for (Key key : keys) {
                ProvisionRequest request;
                ServiceResource resource = null;
                synchronized (collection) {
                    request = collection.get(key);
                    if (request != null && request.getServiceElement() != null) {
                        request.getFailureReasons().clear();
                        resource = Selector.acquireServiceResource(request, context.getSelector());
View Full Code Here

     * @return A ServiceResource that contains an InstantiatorResource that meets the operational criteria of the
     * ServiceElement
     */
    public static ServiceResource acquireServiceResource(final ProvisionRequest request,
                                                         final ServiceResourceSelector selector) {
        ServiceResource resource = null;
        try {
            if (request.getRequestedUuid() != null) {
                resource = selector.getServiceResource(request, request.getRequestedUuid(), true);
                /* If the returned resource is null, then try to get any resource */
                if (resource == null) {
                    resource = selector.getServiceResource(request);
                }

            } else if (request.getExcludeUuid() != null) {
                resource = selector.getServiceResource(request, request.getExcludeUuid(), false);
            } else {
                resource = selector.getServiceResource(request);
            }

            if (resource != null) {
                InstantiatorResource ir = (InstantiatorResource) resource.getResource();
                ir.incrementProvisionCounter(request.getServiceElement());
            }
        } catch (ProvisionException e) {
            if (e.isUninstantiable()) {
                request.setType(ProvisionRequest.Type.UNINSTANTIABLE);
View Full Code Here

     * <code>LandlordLessor</code>. If there are no
     * <code>ServiceResource</code> instances available in the
     * <code>LandlordLessor</code> then a value a null is returned
     */
    protected ServiceResource getNextServiceResource() {
        ServiceResource sr = null;
        try {
            while (true) {
                sr = resourceMgr.getNext();
                if(sr == null)
                    break;
View Full Code Here

     */
    public void fire(final RemoteServiceEvent event) throws NoEventConsumerException {
        event.setEventID(descriptor.eventID);
        event.setSequenceNumber(sequenceNumber);
        while (true) {
            ServiceResource sr = getNextServiceResource();
            if(sr == null)
                throw new NoEventConsumerException("No event consumers");
            try {
                EventRegistrationResource er = (EventRegistrationResource)sr.getResource();
                RemoteEventListener listener = er.getListener();
                MarshalledObject handback = er.getHandback();
                event.setHandback(handback);
                t0 = System.currentTimeMillis();
                listener.notify(event);
                t1 = System.currentTimeMillis();
                sendTime = t1 - t0;
                if(responseWatch != null)
                    responseWatch.setElapsedTime(sendTime, t1);
                sequenceNumber++;
                sent++;
                printStats();
                break;
            } catch(UnknownEventException uee) {
                // We are allowed to cancel the lease here
                try {
                    resourceMgr.removeResource(sr);
                    landlord.cancel(sr.getCookie());
                } catch(Exception ex) {
                    logger.warn("Removing/Cancelling an EventConsumer from UnknownEventException", ex);
                }
            } catch(RemoteException re) {
                // Not sure if we are allowed to cancel the lease here, but
                // the assumption being made here is that if we cant send the
                // notification to the RemoteEventListener then the
                // RemoteEventListener
                // must not be alive. Therefore, cancel the lease
                try {
                    resourceMgr.removeResource(sr);
                    landlord.cancel(sr.getCookie());
                } catch(Exception ex) {
                    logger.warn("Removing/Cancelling an EventConsumer from RemoteException", ex);
                }
            }
        }
View Full Code Here

                                          MarshalledObject handback,
                                          long duration) throws LeaseDeniedException, UnknownEventException {
            eventHandler.register(remote, listener, handback, leaseTime);
            return new EventRegistration(descriptor.eventID,
                                         remote,
                                         landlordLessor.newLease(new ServiceResource(new Object()), leaseTime),
                                         sequenceCounter.incrementAndGet());
        }
View Full Code Here

     */
    public Lease monitor(final long duration) throws LeaseDeniedException {
        if (duration <= 0)
            throw new LeaseDeniedException("lease duration of ["+duration+"] is invalid");
        String phonyResource = this.getClass().getName() + ":"+ System.currentTimeMillis();
        ServiceResource serviceResource = new ServiceResource(phonyResource);
        Lease lease = monitorLandlord.newLease(serviceResource, duration);
        return (lease);
    }
View Full Code Here

        } catch (Throwable t) {
            logger.warn("Registering a ServiceBeanInstantiator", t);
            throw new LeaseDeniedException("Getting ServiceRecords");
        }

        ServiceResource serviceResource = new ServiceResource(resource);

        /* Add ServiceResource to landlord */
        Lease lease = landlord.newLease(serviceResource, duration);       
        EventRegistration registration = new EventRegistration(ServiceProvisionEvent.ID,
                                                               eventSource,
View Full Code Here

                        "Force removal of all Leases", resource.getName());
            landlord.removeAll();
            throw new UnknownLeaseException("Update failed, there are no known leases.");
        }
        boolean updated = false;
        ServiceResource couldNotEnsureLease = null;
        for(ServiceResource svcResource : svcResources) {
            InstantiatorResource ir = (InstantiatorResource) svcResource.getResource();
            logger.trace("Checking for InstantiatorResource match");
            if(ir.getInstantiator().equals(preparedResource)) {
                logger.trace("Update from {}, current serviceCount {}, serviceLimit {}",
                             ir.getName(),
                             deployedServices.size(),
                             serviceLimit);
                logger.trace("Matched InstantiatorResource");
                if(!landlord.ensure(svcResource)) {
                    couldNotEnsureLease = svcResource;
                    break;
                }
                updated = true;
                logger.trace("Set updated resource capabilities");
                ir.setResourceCapability(updatedCapabilities);
                logger.trace("Set serviceLimit to {}", serviceLimit);
                ir.setServiceLimit(serviceLimit);
                try {
                    logger.trace("Set deployedServices, was: {}, updated count is now: {}",
                                  ir.getServiceCount(), deployedServices.size());
                    ir.setDeployedServices(deployedServices);
                } catch (Throwable t) {
                    logger.warn("Getting ServiceRecords from {}", ir.getName(), t);
                }
                /* Process all provision types of Fixed first */
                fixedServiceManager.process(svcResource);
                /* See if any dynamic provision types are pending */
                pendingMgr.process();
                break;
            } else {
                logger.trace("Did not match InstantiatorResource");
            }
        }

        if(couldNotEnsureLease!=null) {
            selector.dropServiceResource(couldNotEnsureLease);
            throw new UnknownLeaseException("Could not ensure lease. Lease expiration: "+couldNotEnsureLease.getExpiration()+", " +
                                            "current time: "+System.currentTimeMillis());
        }
        if(!updated) {
            logger.warn("Update failed, no matching registration found for {}", resource.getName());
            throw new UnknownLeaseException("Update failed, no matching registration found");
View Full Code Here

TOP

Related Classes of org.rioproject.impl.service.ServiceResource

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.