⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servernotifforwarder.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    logger.debug("bufferFilter", "no listeners for this name");                    return;                }                candidates = new IdAndFilter[set.size()];                set.toArray(candidates);            }            // We don't synchronize on targetedNotifs, because it is a local            // variable of our caller and no other thread can see it.            for (IdAndFilter idaf : candidates) {                final NotificationFilter nf = idaf.getFilter();                if (nf == null || nf.isNotificationEnabled(notif)) {                    logger.debug("bufferFilter", "filter matches");                    final TargetedNotification tn =                            new TargetedNotification(notif, idaf.getId());                    if (allowNotificationEmission(source, tn))                        targetedNotifs.add(tn);                }            }        }    };        public NotificationResult fetchNotifs(long startSequenceNumber,        long timeout,        int maxNotifications) {        if (logger.traceOn()) {            logger.trace("fetchNotifs", "Fetching notifications, the " +                "startSequenceNumber is " + startSequenceNumber +                ", the timeout is " + timeout +                ", the maxNotifications is " + maxNotifications);        }                NotificationResult nr = null;        final long t = Math.min(connectionTimeout, timeout);        try {            nr = notifBuffer.fetchNotifications(bufferFilter,                startSequenceNumber,                t, maxNotifications);        } catch (InterruptedException ire) {            nr = new NotificationResult(0L, 0L, new TargetedNotification[0]);        }        if (logger.traceOn()) {            logger.trace("fetchNotifs", "Forwarding the notifs: "+nr);        }                return nr;    }        public void terminate() {        if (logger.traceOn()) {            logger.trace("terminate", "Be called.");        }                synchronized(terminationLock) {            if (terminated) {                return;            }                        terminated = true;                        synchronized(listenerMap) {                listenerMap.clear();            }        }                if (logger.traceOn()) {            logger.trace("terminate", "Terminated.");        }    }        //----------------    // PRIVATE METHODS    //----------------        private void checkState() throws IOException {        synchronized(terminationLock) {            if (terminated) {                throw new IOException("The connection has been terminated.");            }        }    }        private Integer getListenerID() {        synchronized(listenerCounterLock) {            return new Integer(listenerCounter++);        }    }        /**     * Explicitly check the MBeanPermission for     * the current access control context.     */    private void checkMBeanPermission(final ObjectName name,        final String actions)        throws InstanceNotFoundException, SecurityException {        SecurityManager sm = System.getSecurityManager();        if (sm != null) {            AccessControlContext acc = AccessController.getContext();            ObjectInstance oi = null;            try {                oi = (ObjectInstance) AccessController.doPrivileged(                    new PrivilegedExceptionAction() {                    public Object run()                    throws InstanceNotFoundException {                        return mbeanServer.getObjectInstance(name);                    }                });            } catch (PrivilegedActionException e) {                throw (InstanceNotFoundException) extractException(e);            }            String classname = oi.getClassName();            MBeanPermission perm = new MBeanPermission(classname,                null,                name,                actions);            sm.checkPermission(perm, acc);        }    }    /**     * Check if the caller has the right to get the following notifications.     */    private boolean allowNotificationEmission(ObjectName name,                                              TargetedNotification tn) {        try {            if (checkNotificationEmission) {                checkMBeanPermission(name, "addNotificationListener");            }            if (notificationAccessController != null) {                notificationAccessController.fetchNotification(                        connectionId,                        name,                        tn.getNotification(),                        Subject.getSubject(AccessController.getContext()));            }            return true;        } catch (SecurityException e) {            if (logger.debugOn()) {                logger.debug("fetchNotifs", "Notification " +                        tn.getNotification() + " not forwarded: the " +                        "caller didn't have the required access rights");            }            return false;        } catch (Exception e) {            if (logger.debugOn()) {                logger.debug("fetchNotifs", "Notification " +                        tn.getNotification() + " not forwarded: " +                        "got an unexpected exception: " + e);            }            return false;        }    }    /**     * Iterate until we extract the real exception     * from a stack of PrivilegedActionExceptions.     */    private static Exception extractException(Exception e) {        while (e instanceof PrivilegedActionException) {            e = ((PrivilegedActionException)e).getException();        }        return e;    }        private static class IdAndFilter {        private Integer id;        private NotificationFilter filter;        IdAndFilter(Integer id, NotificationFilter filter) {            this.id = id;            this.filter = filter;        }                Integer getId() {            return this.id;        }        NotificationFilter getFilter() {            return this.filter;        }                public int hashCode() {            return id.hashCode();        }                public boolean equals(Object o) {            return ((o instanceof IdAndFilter) &&                    ((IdAndFilter) o).getId().equals(getId()));        }    }        //------------------    // PRIVATE VARIABLES    //------------------        private MBeanServer mbeanServer;    private final String connectionId;        private final long connectionTimeout;        private static int listenerCounter = 0;    private final static int[] listenerCounterLock = new int[0];        private NotificationBuffer notifBuffer;    private Map<ObjectName, Set<IdAndFilter>> listenerMap =            new HashMap<ObjectName, Set<IdAndFilter>>();        private boolean terminated = false;    private final int[] terminationLock = new int[0];        static final String broadcasterClass =        NotificationBroadcaster.class.getName();        private final boolean checkNotificationEmission;    private final NotificationAccessController notificationAccessController;        private static final ClassLogger logger =        new ClassLogger("javax.management.remote.misc", "ServerNotifForwarder");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -