001: /*
002: *
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.jumpimpl.module.multimedia;
028:
029: import java.util.Map;
030: import java.util.Vector;
031: import java.util.Enumeration;
032: import java.io.IOException;
033: import com.sun.jump.module.JUMPModule;
034: import com.sun.jump.os.JUMPOSInterface;
035: import com.sun.jump.message.JUMPMessageHandler;
036: import com.sun.jump.message.JUMPMessage;
037: import com.sun.jump.message.JUMPMessageDispatcher;
038: import com.sun.jump.message.JUMPMessageDispatcherTypeException;
039: import com.sun.jump.command.JUMPRequest;
040: import com.sun.jump.message.JUMPOutgoingMessage;
041: import com.sun.jump.executive.JUMPExecutive;
042: import com.sun.jump.executive.JUMPIsolateProxy;
043: import com.sun.jump.executive.JUMPIsolateFactory;
044: import com.sun.jump.module.eventqueue.JUMPEventQueueModuleFactory;
045: import com.sun.jump.module.eventqueue.JUMPEventQueueModule;
046: import com.sun.jump.module.eventqueue.JUMPEventHandler;
047:
048: /**
049: * Implementation of Multimedia module.
050: * This class performs the following activities:
051: * <ul>
052: * <li>starts native file system monitoring;</li>
053: * <li>listens to multimedia events from the platform;</li>
054: * <li>notifies related isolates via JUMP messages.</li>
055: * </ul>
056: */
057: public class MultimediaModuleImpl implements JUMPModule,
058: JUMPEventHandler {
059: /** Message type for Multimedia events. */
060: public static final String MESSAGE_TYPE = "mvm/multimedia";
061:
062: /** Message ID for notifications from Multimedia monitor. */
063: public static final String MM_EVENT = "mm_event";
064:
065: /** Executive process for messaging. */
066: private JUMPExecutive this Process;
067:
068: /** Isolate manager for getting <code>JUMPIsolateProxy</code> instances. */
069: JUMPIsolateFactory isolateFactory;
070:
071: /**
072: * Loads the Multimedia module. Performs necessary initialization to start
073: * monitoring Multimedia events.
074: *
075: * @param config configuration data (ignored).
076: */
077: public void load(Map config) {
078: // Register this module as event handler for JSR-135.
079: JUMPEventQueueModule eventQueue = JUMPEventQueueModuleFactory
080: .getInstance().getModule();
081: eventQueue.registerEventHandler(135, this );
082: // Get executive instance.
083: this Process = JUMPExecutive.getInstance();
084: }
085:
086: /**
087: * Unloads the Multimedia module.
088: */
089: public void unload() {
090: }
091:
092: /**
093: * Handles incoming events from event queue module. All native events
094: * related to Multimedia should be delivered here.
095: *
096: * @param id event identifier.
097: * @param data event data.
098: */
099: public void handleEvent(int id, byte[] data) {
100: // Parse event data to get IsolateId
101: int isolateId = id;
102: if (isolateFactory == null) {
103: isolateFactory = this Process.getIsolateFactory();
104: }
105:
106: JUMPIsolateProxy ip = isolateFactory.getIsolate(isolateId);
107: // Pre-create message for isolate notifications.
108: JUMPRequest eventCmd = new JUMPRequest(MESSAGE_TYPE, MM_EVENT);
109: JUMPOutgoingMessage notification = eventCmd
110: .toMessage(this Process);
111:
112: notification.addByteArray(data);
113: try {
114: ip.sendMessage(notification);
115: } catch (IOException ex) {
116: System.out.println("==> Can not send MMEvent: "
117: + ex.getMessage());
118: }
119: }
120: }
|