this.preEventItem = new ServiceItem(preEventItem.serviceID, preEventItem.service, preEventItem.attributeSets); if (postEventItem != null) this.postEventItem = new ServiceItem(postEventItem.serviceID, postEventItem.service, postEventItem.attributeSets);
/** * @param filteredItem the filteredItem to set */ public void setFilteredItem(ServiceItem filteredItem) { this.filteredItem = filteredItem == null ? null : filteredItem.clone(); }
private boolean isLookupService(ServiceItemReg itemReg) { boolean isLookupService = false; synchronized (itemReg) { if (itemReg.item.getService() instanceof ServiceRegistrar) { isLookupService = true; } } return isLookupService; } }//end class LookupCacheImpl.ProxyRegDropTask
ServiceItem [] processBootStrapProxys(Object [] proxys){ int length = proxys.length; Collection<ServiceItem> result = new ArrayList<ServiceItem>(length); for (int i = 0; i < length; i++){ Object bootstrap; Entry [] attributes; ServiceID id; try { bootstrap = sdm.bootstrapProxyPreparer.prepareProxy(proxys[i]); attributes = ((ServiceAttributesAccessor) bootstrap).getServiceAttributes(); id = ((ServiceIDAccessor) bootstrap).serviceID(); result.add(new ServiceItem(id, bootstrap, attributes)); } catch (IOException ex) { } //ignore } return result.toArray(new ServiceItem[result.size()]); }
/** * @return the filteredItem */ public ServiceItem getFilteredItem() { return filteredItem == null ? null : filteredItem.clone(); }
/** * @return can return {@link ServiceReplicationStatus#UNKNOWN} or {@link * ServiceReplicationStatus#UNREACHABLE_TARGET} */ private ServiceReplicationStatus getServiceReplicationStatus(ServiceItem serviceItem, Map<String, OutgoingChannel> allOutgoingReplicationChannels) { Object service = serviceItem.getService(); if (!(service instanceof ISpaceProxy)) return ServiceReplicationStatus.UNKNOWN; ServiceReplicationStatus serviceReplicationStatus = calculateServiceReplicationStatus((ISpaceProxy) service, serviceItem, allOutgoingReplicationChannels); if (_logger.isLoggable(Level.FINER)) _logger.finer("calculated replication status for " + serviceItem + " is " + serviceReplicationStatus); return serviceReplicationStatus; }
/** * Forcefully make this space to be primary */ public void forceMoveToPrimary() throws RemoteException { if (getState() == State.ACTIVE) return; changeState(State.PENDING, State.ACTIVE, true /* force */); notifyListenerOnActive(new ServiceItem(_electTemplate.getServiceID(), _electTemplate.getService(), null /* entry[] */)); }
private ServiceDiscoveryEvent( Object source, ServiceItem preEventItem, ServiceItem postEventItem, boolean check) { super(source); if(preEventItem != null) this.preEventItem = preEventItem.clone(); else this.preEventItem = null; if(postEventItem != null) this.postEventItem = postEventItem.clone(); else this.postEventItem = null; }
private void removeUnavailableServices( final List<ServiceItem> services) { // check service accessibility for (Iterator<ServiceItem> iterator = services.iterator(); iterator.hasNext(); ) { ServiceItem serviceItem = iterator.next(); IJSpace primarySpace = (IJSpace) serviceItem.getService(); try { primarySpace.ping(); } catch (RemoteException e) { if (_logger.isLoggable(Level.FINE)) _logger.fine("Primary space [] is not available, ignoring it in election process."); iterator.remove(); } } } }
public ServiceItem get(Collection context){ Object obj = null; try { obj = service.get(null, null, context); } catch (Throwable e) { RegistrarProxy.handleException(e); } synchronized (this){ return new ServiceItem(serviceID, obj, EntryRep.toEntry(attributeSets)); } }
/** * Returns an instance of a <code>ServiceItem</code> containing the * service reference corresponding to the given event. The service * state reflected in the returned service item is the state of the * service after the occurrence of the event. * <p> * If the event is a removal event, then this method will return * <code>null</code> because the discovered service has no state in * the cache after it is removed from the cache. * <p> * Because making a copy can be a very expensive process, this * method does not return a copy of the service reference associated * with the given event. Rather, it returns the appropriate service * reference from the cache itself. Due to this cost, listeners that * receive a <code>ServiceDiscoveryEvent</code> must not modify the * contents of the object returned by this method; doing so could * cause the state of the cache to become corrupted or inconsistent * because the objects returned by this method are also members of * the cache. This potential for corruption or inconsistency is why * the effects of modifying the object returned by this accessor * method are undefined. * * @return ServiceItem containing the service reference corresponding * to the given event. */ public ServiceItem getPostEventServiceItem() { return postEventItem.clone(); }
private void logSplitBrainDetection(List<ServiceItem> splitActives) { if (_logger.isLoggable(Level.WARNING)) { StringBuilder logBuf = new StringBuilder(); //noinspection StringConcatenationInsideStringBufferAppend logBuf.append("Split-Brain detected by space instance [" + _electTemplate.service + "]. There is more than one primary space. Primary spaces are:\n"); for (int i = 0; i < splitActives.size(); i++) { ServiceItem activeServiceItem = splitActives.get(i); String activeHost = HostName.getHostNameFrom(activeServiceItem.attributeSets); Object service = activeServiceItem.getService(); logBuf.append(" ").append(i + 1).append(". [") .append(service) .append("] space"); if (activeHost != null) logBuf.append(" on [") .append(activeHost) .append("] machine."); logBuf.append("\n"); } _logger.warning(logBuf.toString()); } }
synchronized (itemReg) { if (itemReg.filteredItem == null) { item = new ServiceItem ((itemReg.item).serviceID, (itemReg.item).service, (itemReg.item).attributeSets); filteredItem = new ServiceItem ((itemReg.item).serviceID, (itemReg.item).service,
/** * Returns an instance of a <code>ServiceItem</code> containing the * service reference corresponding to the given event. The service * state reflected in the returned service item is the state of the * service prior to the occurrence of the event. * <p> * If the event is a discovery event (as opposed to a removal or * modification event), then this method will return <code>null</code> * because the discovered service had no state in the cache prior to * its discovery. * <p> * Because making a copy can be a very expensive process, this * method does not return a copy of the service reference associated * with the given event. Rather, it returns the appropriate service * reference from the cache itself. Due to this cost, listeners that * receive a <code>ServiceDiscoveryEvent</code> must not modify the * contents of the object returned by this method; doing so could * cause the state of the cache to become corrupted or inconsistent * because the objects returned by this method are also members of * the cache. This potential for corruption or inconsistency is why * the effects of modifying the object returned by this accessor * method are undefined. * * @return ServiceItem containing the service reference corresponding * to the given event. */ public ServiceItem getPreEventServiceItem() { return preEventItem.clone(); }
private void logSplitBrainResolution( List<SplitBrainServiceEntry> splitBrainServiceEntries, SplitBrainServiceEntry electedPrimary) { if (_logger.isLoggable(Level.INFO)) { String resolutionReason = getResolutionReason(splitBrainServiceEntries); Object service = electedPrimary.getService().getService(); StringBuilder sb = new StringBuilder(); sb.append("Split brain was resolved - ").append(service).append(" was chosen because - ").append(resolutionReason).append(".\n"); sb.append(" Split-brain resolution priority list ["); sb.append(StringUtils.NEW_LINE); for (int i = 0; i < splitBrainServiceEntries.size(); i++) { SplitBrainServiceEntry serviceEntry = splitBrainServiceEntries.get(i); sb.append(i + 1).append(". "); sb.append(serviceEntry.toString()); sb.append(StringUtils.NEW_LINE); } sb.append("]"); _logger.info(sb.toString()); } }
/** * Convert back to a ServiceItem. If the service object cannot be constructed, it is set to * null. If an Entry cannot be constructed, it is set to null. If a field of an Entry cannot * be unmarshalled, it is set to null. */ public ServiceItem get() { Object obj = null; try { obj = service.get(); } catch (Throwable e) { RegistrarProxy.handleException(e); } return new ServiceItem(serviceID, obj, EntryRep.toEntry(attributeSets)); }
/** * Returns the new state of the serviceItem, or null if the serviceItem was deleted * from the lookup service. * * @return the new state of the serviceItem, or null if the serviceItem was deleted * from the lookup service. */ @Override public ServiceItem getServiceItem() { if (serviceItem instanceof ServiceItem){ return ((ServiceItem) serviceItem).clone(); } else if (serviceItem instanceof Item) { bootstrap = ((Item)serviceItem).getProxy(); serviceItem = ((Item)serviceItem).get(); return ((ServiceItem) serviceItem).clone(); } return null; }
@Override public String toString() { StringBuilder logBuf = new StringBuilder(); String host = HostName.getHostNameFrom(_service.attributeSets); Object service = _service.getService(); logBuf.append("[") .append(service) .append("] space"); if (host != null) logBuf.append(" on [") .append(host) .append("] machine"); logBuf.append(" [pid="); logBuf.append(_replicationStatus.getProcessId()); logBuf.append("]"); logBuf.append(StringUtils.NEW_LINE); logBuf.append("Service properties = ").append(StringUtils.NEW_LINE); logBuf.append("{"); logBuf.append(_replicationStatus).append(StringUtils.NEW_LINE); logBuf.append("}"); return logBuf.toString(); }
|| (itemReg.filteredItem == null)) continue; itemToFilter = new ServiceItem ((itemReg.filteredItem).serviceID, (itemReg.filteredItem).service,
@Override public void accept(ServiceID sid, ServiceItemReg itemReg) { ServiceItem itemToFilter = itemReg.getFilteredItem(); if ((itemToFilter == null) || (itemReg.isDiscarded())) return; /* Make a copy because the filter may change it to null */ /* ServiceItemReg now performs defensive copy clone for us, * so we don't forget. */ itemToFilter = itemToFilter.clone(); /* Apply the filter */ boolean pass = (filter2 == null) || (filter2.check(itemToFilter)); /* Handle filter fail - skip to next item */ if (!pass) return; /* Handle filter pass - add item to return set */ if (itemToFilter.service != null) { items.add(itemToFilter); return; } //endif(pass) /* Handle filter indefinite - discard the item */ Discard dis = new Discard( cache, itemReg, itemToFilter, cache.sdm.getDiscardWait() ); cache.serviceIdMap.computeIfPresent(sid, dis); }