001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.stats;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010: import org.jasig.portal.ChannelDefinition;
011: import org.jasig.portal.UserProfile;
012: import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
013: import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
014: import org.jasig.portal.security.IPerson;
015:
016: /**
017: * IStatsRecorder implementation which delegates to zero to many child IStatsRecorders.
018: * This class allows you to use multiple stats recorders.
019: *
020: * We invoke each child IStatsRecorder within a try-catch Throwable in order to
021: * guarantee that no particular IStatsRecorder's failure will prevent propogation of
022: * IStatsRecorder events to other children. We do not propogate these exceptions
023: * to our caller in order to prevent failures in statistics recording from propogating
024: * into other modules. (For instance, a failure to record a login shouldn't
025: * prevent a user from being able to log in at all.)
026: *
027: * @version $Revision: 36546 $ $Date: 2006-04-11 12:18:23 -0700 (Tue, 11 Apr 2006) $
028: * @since uPortal 2.5.1
029: *
030: * @deprecated IStatsRecorder implementation is replaced with a much more flexible system based on the Spring ApplicationEventPublisher
031: * and Event Listeners. For more information see:
032: * http://www.ja-sig.org/wiki/display/UPC/Proposal+to+Deprecate+IStatsRecorder
033: */
034: public final class ListStatsRecorder implements IStatsRecorder {
035:
036: private final Log log = LogFactory.getLog(getClass());
037:
038: /**
039: * Recorders to which we broadcast IStatsRecorder method calls, in order.
040: */
041: private IStatsRecorder[] children = new IStatsRecorder[0];
042:
043: /**
044: * Get the recorders to which we broadcast IStatsRecorder method calls.
045: * @return recorders to which we broadcast IStatsRecorder method calls.
046: */
047: public IStatsRecorder[] getChildren() {
048: return this .children;
049: }
050:
051: /**
052: * Set the recorders to which we broadcast IStatsRecorder method calls.
053: * @param children to which we will broadcast IStatsRecorder method calls.
054: */
055: public void setChildren(IStatsRecorder[] children) {
056: if (children == null) {
057: throw new IllegalArgumentException(
058: "Cannot set children to null.");
059: }
060: this .children = children;
061: }
062:
063: public void recordLogin(IPerson person) {
064: // defensive local reference so that if something injects a new array of targets
065: // while we're iterating, the length of the array we're iterating over cannot change
066: IStatsRecorder[] targets = this .children;
067:
068: for (int i = 0; i < targets.length; i++) {
069: IStatsRecorder target = targets[i];
070: if (target == null) {
071: log
072: .error("Cannot propogate recordLogin() to a null IStatsRecorder (array element "
073: + i + ")");
074: } else {
075: try {
076: target.recordLogin(person);
077: } catch (Throwable t) {
078: // no matter what went wrong, we log it and then try the remaining
079: // IStatsRecorder event handlers. No recorder's failure should prevent
080: // our trying the other recorders, and no recorder's failure should
081: // be propogated to our caller.
082: log.error("Error propogating recordLogin() to "
083: + target, t);
084: }
085: }
086: }
087:
088: }
089:
090: public void recordLogout(IPerson person) {
091: // defensive local reference so that if something injects a new array of targets
092: // while we're iterating, the length of the array we're iterating over cannot change
093: IStatsRecorder[] targets = this .children;
094:
095: for (int i = 0; i < targets.length; i++) {
096: IStatsRecorder target = targets[i];
097: if (target == null) {
098: log
099: .error("Cannot propogate recordLogout() to a null IStatsRecorder (array element "
100: + i + ")");
101: } else {
102: try {
103: target.recordLogout(person);
104: } catch (Throwable t) {
105: // no matter what went wrong, we log it and then try the remaining
106: // IStatsRecorder event handlers. No recorder's failure should prevent
107: // our trying the other recorders, and no recorder's failure should
108: // be propogated to our caller.
109: log.error("Error propogating recordLogout() to "
110: + target, t);
111: }
112: }
113: }
114: }
115:
116: public void recordSessionCreated(IPerson person) {
117: // defensive local reference so that if something injects a new array of targets
118: // while we're iterating, the length of the array we're iterating over cannot change
119: IStatsRecorder[] targets = this .children;
120:
121: for (int i = 0; i < targets.length; i++) {
122: IStatsRecorder target = targets[i];
123: if (target == null) {
124: log
125: .error("Cannot propogate recordSessionCreated() to a null IStatsRecorder (array element "
126: + i + ")");
127: } else {
128: try {
129: target.recordSessionCreated(person);
130: } catch (Throwable t) {
131: // no matter what went wrong, we log it and then try the remaining
132: // IStatsRecorder event handlers. No recorder's failure should prevent
133: // our trying the other recorders, and no recorder's failure should
134: // be propogated to our caller.
135: log.error(
136: "Error propogating recordSessionCreated() to "
137: + target, t);
138: }
139: }
140: }
141: }
142:
143: public void recordSessionDestroyed(IPerson person) {
144: // defensive local reference so that if something injects a new array of targets
145: // while we're iterating, the length of the array we're iterating over cannot change
146: IStatsRecorder[] targets = this .children;
147:
148: for (int i = 0; i < targets.length; i++) {
149: IStatsRecorder target = targets[i];
150: if (target == null) {
151: log
152: .error("Cannot propogate recordSessionDestroyed() to a null IStatsRecorder (array element "
153: + i + ")");
154: } else {
155: try {
156: target.recordSessionDestroyed(person);
157: } catch (Throwable t) {
158: // no matter what went wrong, we log it and then try the remaining
159: // IStatsRecorder event handlers. No recorder's failure should prevent
160: // our trying the other recorders, and no recorder's failure should
161: // be propogated to our caller.
162: log.error(
163: "Error propogating recordSessionDestroyed() to "
164: + target, t);
165: }
166: }
167: }
168: }
169:
170: public void recordChannelDefinitionPublished(IPerson person,
171: ChannelDefinition channelDef) {
172: // defensive local reference so that if something injects a new array of targets
173: // while we're iterating, the length of the array we're iterating over cannot change
174: IStatsRecorder[] targets = this .children;
175:
176: for (int i = 0; i < targets.length; i++) {
177: IStatsRecorder target = targets[i];
178: if (target == null) {
179: log
180: .error("Cannot propogate recordChannelDefinitionPublished() to a null IStatsRecorder (array element "
181: + i + ")");
182: } else {
183: try {
184: target.recordChannelDefinitionPublished(person,
185: channelDef);
186: } catch (Throwable t) {
187: // no matter what went wrong, we log it and then try the remaining
188: // IStatsRecorder event handlers. No recorder's failure should prevent
189: // our trying the other recorders, and no recorder's failure should
190: // be propogated to our caller.
191: log.error(
192: "Error propogating recordChannelDefinitionPublished() to "
193: + target, t);
194: }
195: }
196: }
197: }
198:
199: public void recordChannelDefinitionModified(IPerson person,
200: ChannelDefinition channelDef) {
201: // defensive local reference so that if something injects a new array of targets
202: // while we're iterating, the length of the array we're iterating over cannot change
203: IStatsRecorder[] targets = this .children;
204:
205: for (int i = 0; i < targets.length; i++) {
206: IStatsRecorder target = targets[i];
207: if (target == null) {
208: log
209: .error("Cannot propogate recordChannelDefinitionModified() to a null IStatsRecorder (array element "
210: + i + ")");
211: } else {
212: try {
213: target.recordChannelDefinitionModified(person,
214: channelDef);
215: } catch (Throwable t) {
216: // no matter what went wrong, we log it and then try the remaining
217: // IStatsRecorder event handlers. No recorder's failure should prevent
218: // our trying the other recorders, and no recorder's failure should
219: // be propogated to our caller.
220: log.error(
221: "Error propogating recordChannelDefinitionModified() to "
222: + target, t);
223: }
224: }
225: }
226: }
227:
228: public void recordChannelDefinitionRemoved(IPerson person,
229: ChannelDefinition channelDef) {
230: // defensive local reference so that if something injects a new array of targets
231: // while we're iterating, the length of the array we're iterating over cannot change
232: IStatsRecorder[] targets = this .children;
233:
234: for (int i = 0; i < targets.length; i++) {
235: IStatsRecorder target = targets[i];
236: if (target == null) {
237: log
238: .error("Cannot propogate recordSessionDestroyed() to a null IStatsRecorder (array element "
239: + i + ")");
240: } else {
241: try {
242: target.recordChannelDefinitionRemoved(person,
243: channelDef);
244: } catch (Throwable t) {
245: // no matter what went wrong, we log it and then try the remaining
246: // IStatsRecorder event handlers. No recorder's failure should prevent
247: // our trying the other recorders, and no recorder's failure should
248: // be propogated to our caller.
249: log.error(
250: "Error propogating recordSessionDestroyed() to "
251: + target, t);
252: }
253: }
254: }
255: }
256:
257: public void recordChannelAddedToLayout(IPerson person,
258: UserProfile profile,
259: IUserLayoutChannelDescription channelDesc) {
260: // defensive local reference so that if something injects a new array of targets
261: // while we're iterating, the length of the array we're iterating over cannot change
262: IStatsRecorder[] targets = this .children;
263:
264: for (int i = 0; i < targets.length; i++) {
265: IStatsRecorder target = targets[i];
266: if (target == null) {
267: log
268: .error("Cannot propogate recordChannelAddedToLayout() to a null IStatsRecorder (array element "
269: + i + ")");
270: } else {
271: try {
272: target.recordChannelAddedToLayout(person, profile,
273: channelDesc);
274: } catch (Throwable t) {
275: // no matter what went wrong, we log it and then try the remaining
276: // IStatsRecorder event handlers. No recorder's failure should prevent
277: // our trying the other recorders, and no recorder's failure should
278: // be propogated to our caller.
279: log.error(
280: "Error propogating recordChannelAddedToLayout() to "
281: + target, t);
282: }
283: }
284: }
285: }
286:
287: public void recordChannelUpdatedInLayout(IPerson person,
288: UserProfile profile,
289: IUserLayoutChannelDescription channelDesc) {
290: // defensive local reference so that if something injects a new array of targets
291: // while we're iterating, the length of the array we're iterating over cannot change
292: IStatsRecorder[] targets = this .children;
293:
294: for (int i = 0; i < targets.length; i++) {
295: IStatsRecorder target = targets[i];
296: if (target == null) {
297: log
298: .error("Cannot propogate recordChannelUpdatedInLayout() to a null IStatsRecorder (array element "
299: + i + ")");
300: } else {
301: try {
302: target.recordChannelUpdatedInLayout(person,
303: profile, channelDesc);
304: } catch (Throwable t) {
305: // no matter what went wrong, we log it and then try the remaining
306: // IStatsRecorder event handlers. No recorder's failure should prevent
307: // our trying the other recorders, and no recorder's failure should
308: // be propogated to our caller.
309: log.error(
310: "Error propogating recordChannelUpdatedInLayout() to "
311: + target, t);
312: }
313: }
314: }
315: }
316:
317: public void recordChannelMovedInLayout(IPerson person,
318: UserProfile profile,
319: IUserLayoutChannelDescription channelDesc) {
320: // defensive local reference so that if something injects a new array of targets
321: // while we're iterating, the length of the array we're iterating over cannot change
322: IStatsRecorder[] targets = this .children;
323:
324: for (int i = 0; i < targets.length; i++) {
325: IStatsRecorder target = targets[i];
326: if (target == null) {
327: log
328: .error("Cannot propogate recordChannelMovedInLayout() to a null IStatsRecorder (array element "
329: + i + ")");
330: } else {
331: try {
332: target.recordChannelMovedInLayout(person, profile,
333: channelDesc);
334: } catch (Throwable t) {
335: // no matter what went wrong, we log it and then try the remaining
336: // IStatsRecorder event handlers. No recorder's failure should prevent
337: // our trying the other recorders, and no recorder's failure should
338: // be propogated to our caller.
339: log.error(
340: "Error propogating recordChannelMovedInLayout() to "
341: + target, t);
342: }
343: }
344: }
345: }
346:
347: public void recordChannelRemovedFromLayout(IPerson person,
348: UserProfile profile,
349: IUserLayoutChannelDescription channelDesc) {
350: // defensive local reference so that if something injects a new array of targets
351: // while we're iterating, the length of the array we're iterating over cannot change
352: IStatsRecorder[] targets = this .children;
353:
354: for (int i = 0; i < targets.length; i++) {
355: IStatsRecorder target = targets[i];
356: if (target == null) {
357: log
358: .error("Cannot propogate recordChannelRemovedFromLayout() to a null IStatsRecorder (array element "
359: + i + ")");
360: } else {
361: try {
362: target.recordChannelRemovedFromLayout(person,
363: profile, channelDesc);
364: } catch (Throwable t) {
365: // no matter what went wrong, we log it and then try the remaining
366: // IStatsRecorder event handlers. No recorder's failure should prevent
367: // our trying the other recorders, and no recorder's failure should
368: // be propogated to our caller.
369: log.error(
370: "Error propogating recordCHannelRemovedFromLayout() to "
371: + target, t);
372: }
373: }
374: }
375: }
376:
377: public void recordFolderAddedToLayout(IPerson person,
378: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
379: // defensive local reference so that if something injects a new array of targets
380: // while we're iterating, the length of the array we're iterating over cannot change
381: IStatsRecorder[] targets = this .children;
382:
383: for (int i = 0; i < targets.length; i++) {
384: IStatsRecorder target = targets[i];
385: if (target == null) {
386: log
387: .error("Cannot propogate recordFolderAddedToLayout() to a null IStatsRecorder (array element "
388: + i + ")");
389: } else {
390: try {
391: target.recordFolderAddedToLayout(person, profile,
392: folderDesc);
393: } catch (Throwable t) {
394: // no matter what went wrong, we log it and then try the remaining
395: // IStatsRecorder event handlers. No recorder's failure should prevent
396: // our trying the other recorders, and no recorder's failure should
397: // be propogated to our caller.
398: log.error(
399: "Error propogating recordFolderAddedToLayout() to "
400: + target, t);
401: }
402: }
403: }
404: }
405:
406: public void recordFolderUpdatedInLayout(IPerson person,
407: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
408: // defensive local reference so that if something injects a new array of targets
409: // while we're iterating, the length of the array we're iterating over cannot change
410: IStatsRecorder[] targets = this .children;
411:
412: for (int i = 0; i < targets.length; i++) {
413: IStatsRecorder target = targets[i];
414: if (target == null) {
415: log
416: .error("Cannot propogate recordFolderUpdatedInLayout() to a null IStatsRecorder (array element "
417: + i + ")");
418: } else {
419: try {
420: target.recordFolderUpdatedInLayout(person, profile,
421: folderDesc);
422: } catch (Throwable t) {
423: // no matter what went wrong, we log it and then try the remaining
424: // IStatsRecorder event handlers. No recorder's failure should prevent
425: // our trying the other recorders, and no recorder's failure should
426: // be propogated to our caller.
427: log.error(
428: "Error propogating recordFolderUpdatedInLayout() to "
429: + target, t);
430: }
431: }
432: }
433: }
434:
435: public void recordFolderMovedInLayout(IPerson person,
436: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
437: // defensive local reference so that if something injects a new array of targets
438: // while we're iterating, the length of the array we're iterating over cannot change
439: IStatsRecorder[] targets = this .children;
440:
441: for (int i = 0; i < targets.length; i++) {
442: IStatsRecorder target = targets[i];
443: if (target == null) {
444: log
445: .error("Cannot propogate recordFolderMovedInLayout() to a null IStatsRecorder (array element "
446: + i + ")");
447: } else {
448: try {
449: target.recordFolderMovedInLayout(person, profile,
450: folderDesc);
451: } catch (Throwable t) {
452: // no matter what went wrong, we log it and then try the remaining
453: // IStatsRecorder event handlers. No recorder's failure should prevent
454: // our trying the other recorders, and no recorder's failure should
455: // be propogated to our caller.
456: log.error(
457: "Error propogating recordFolderMovedInLayout() to "
458: + target, t);
459: }
460: }
461: }
462: }
463:
464: public void recordFolderRemovedFromLayout(IPerson person,
465: UserProfile profile, IUserLayoutFolderDescription folderDesc) {
466: // defensive local reference so that if something injects a new array of targets
467: // while we're iterating, the length of the array we're iterating over cannot change
468: IStatsRecorder[] targets = this .children;
469:
470: for (int i = 0; i < targets.length; i++) {
471: IStatsRecorder target = targets[i];
472: if (target == null) {
473: log
474: .error("Cannot propogate recordFolderRemovedFromLayout() to a null IStatsRecorder (array element "
475: + i + ")");
476: } else {
477: try {
478: target.recordFolderRemovedFromLayout(person,
479: profile, folderDesc);
480: } catch (Throwable t) {
481: // no matter what went wrong, we log it and then try the remaining
482: // IStatsRecorder event handlers. No recorder's failure should prevent
483: // our trying the other recorders, and no recorder's failure should
484: // be propogated to our caller.
485: log.error(
486: "Error propogating recordFolderRemovedFromLayout() to "
487: + target, t);
488: }
489: }
490: }
491: }
492:
493: public void recordChannelInstantiated(IPerson person,
494: UserProfile profile,
495: IUserLayoutChannelDescription channelDesc) {
496: // defensive local reference so that if something injects a new array of targets
497: // while we're iterating, the length of the array we're iterating over cannot change
498: IStatsRecorder[] targets = this .children;
499:
500: for (int i = 0; i < targets.length; i++) {
501: IStatsRecorder target = targets[i];
502: if (target == null) {
503: log
504: .error("Cannot propogate recordChannelInstantiated() to a null IStatsRecorder (array element "
505: + i + ")");
506: } else {
507: try {
508: target.recordChannelInstantiated(person, profile,
509: channelDesc);
510: } catch (Throwable t) {
511: // no matter what went wrong, we log it and then try the remaining
512: // IStatsRecorder event handlers. No recorder's failure should prevent
513: // our trying the other recorders, and no recorder's failure should
514: // be propogated to our caller.
515: log.error(
516: "Error propogating recordChannelInstantiated() to "
517: + target, t);
518: }
519: }
520: }
521: }
522:
523: public void recordChannelRendered(IPerson person,
524: UserProfile profile,
525: IUserLayoutChannelDescription channelDesc) {
526: // defensive local reference so that if something injects a new array of targets
527: // while we're iterating, the length of the array we're iterating over cannot change
528: IStatsRecorder[] targets = this .children;
529:
530: for (int i = 0; i < targets.length; i++) {
531: IStatsRecorder target = targets[i];
532: if (target == null) {
533: log
534: .error("Cannot propogate recordChannelRendered() to a null IStatsRecorder (array element "
535: + i + ")");
536: } else {
537: try {
538: target.recordChannelRendered(person, profile,
539: channelDesc);
540: } catch (Throwable t) {
541: // no matter what went wrong, we log it and then try the remaining
542: // IStatsRecorder event handlers. No recorder's failure should prevent
543: // our trying the other recorders, and no recorder's failure should
544: // be propogated to our caller.
545: log.error(
546: "Error propogating recordChannelRendered() to "
547: + target, t);
548: }
549: }
550: }
551: }
552:
553: public void recordChannelTargeted(IPerson person,
554: UserProfile profile,
555: IUserLayoutChannelDescription channelDesc) {
556: // defensive local reference so that if something injects a new array of targets
557: // while we're iterating, the length of the array we're iterating over cannot change
558: IStatsRecorder[] targets = this .children;
559:
560: for (int i = 0; i < targets.length; i++) {
561: IStatsRecorder target = targets[i];
562: if (target == null) {
563: log
564: .error("Cannot propogate recordChannelTargeted() to a null IStatsRecorder (array element "
565: + i + ")");
566: } else {
567: try {
568: target.recordChannelTargeted(person, profile,
569: channelDesc);
570: } catch (Throwable t) {
571: // no matter what went wrong, we log it and then try the remaining
572: // IStatsRecorder event handlers. No recorder's failure should prevent
573: // our trying the other recorders, and no recorder's failure should
574: // be propogated to our caller.
575: log.error(
576: "Error propogating recordChannelTargeted() to "
577: + target, t);
578: }
579: }
580: }
581: }
582:
583: }
|