Thu, 12 Mar 2009 18:16:36 -0700
Merge
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // The AttachListener thread services a queue of operations that are enqueued |
duke@435 | 26 | // by client tools. Each operation is identified by a name and has up to 3 |
duke@435 | 27 | // arguments. The operation name is mapped to a function which performs the |
duke@435 | 28 | // operation. The function is called with an outputStream which is can use to |
duke@435 | 29 | // write any result data (for examples the properties command serializes |
duke@435 | 30 | // properties names and values to the output stream). When the function |
duke@435 | 31 | // complets the result value and any result data is returned to the client |
duke@435 | 32 | // tool. |
duke@435 | 33 | |
duke@435 | 34 | #ifndef SERVICES_KERNEL |
duke@435 | 35 | |
duke@435 | 36 | class AttachOperation; |
duke@435 | 37 | |
duke@435 | 38 | typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out); |
duke@435 | 39 | |
duke@435 | 40 | struct AttachOperationFunctionInfo { |
duke@435 | 41 | const char* name; |
duke@435 | 42 | AttachOperationFunction func; |
duke@435 | 43 | }; |
duke@435 | 44 | #endif // SERVICES_KERNEL |
duke@435 | 45 | |
duke@435 | 46 | class AttachListener: AllStatic { |
duke@435 | 47 | public: |
duke@435 | 48 | static void init() KERNEL_RETURN; |
duke@435 | 49 | static void abort() KERNEL_RETURN; |
duke@435 | 50 | |
duke@435 | 51 | // invoke to perform clean-up tasks when all clients detach |
duke@435 | 52 | static void detachall() KERNEL_RETURN; |
duke@435 | 53 | |
duke@435 | 54 | // indicates if the Attach Listener needs to be created at startup |
duke@435 | 55 | static bool init_at_startup() KERNEL_RETURN_(return false;); |
duke@435 | 56 | |
duke@435 | 57 | // indicates if we have a trigger to start the Attach Listener |
duke@435 | 58 | static bool is_init_trigger() KERNEL_RETURN_(return false;); |
duke@435 | 59 | |
duke@435 | 60 | #ifdef SERVICES_KERNEL |
duke@435 | 61 | static bool is_attach_supported() { return false; } |
duke@435 | 62 | #else // SERVICES_KERNEL |
duke@435 | 63 | private: |
duke@435 | 64 | static volatile bool _initialized; |
duke@435 | 65 | |
duke@435 | 66 | public: |
duke@435 | 67 | static bool is_initialized() { return _initialized; } |
duke@435 | 68 | static void set_initialized() { _initialized = true; } |
duke@435 | 69 | |
duke@435 | 70 | // indicates if this VM supports attach-on-demand |
duke@435 | 71 | static bool is_attach_supported() { return !DisableAttachMechanism; } |
duke@435 | 72 | |
duke@435 | 73 | // platform specific initialization |
duke@435 | 74 | static int pd_init(); |
duke@435 | 75 | |
duke@435 | 76 | // platform specific operation |
duke@435 | 77 | static AttachOperationFunctionInfo* pd_find_operation(const char* name); |
duke@435 | 78 | |
duke@435 | 79 | // platform specific flag change |
duke@435 | 80 | static jint pd_set_flag(AttachOperation* op, outputStream* out); |
duke@435 | 81 | |
duke@435 | 82 | // platform specific detachall |
duke@435 | 83 | static void pd_detachall(); |
duke@435 | 84 | |
duke@435 | 85 | // platform specific data dump |
duke@435 | 86 | static void pd_data_dump(); |
duke@435 | 87 | |
duke@435 | 88 | // dequeue the next operation |
duke@435 | 89 | static AttachOperation* dequeue(); |
duke@435 | 90 | #endif // SERVICES_KERNEL |
duke@435 | 91 | }; |
duke@435 | 92 | |
duke@435 | 93 | #ifndef SERVICES_KERNEL |
duke@435 | 94 | class AttachOperation: public CHeapObj { |
duke@435 | 95 | public: |
duke@435 | 96 | enum { |
duke@435 | 97 | name_length_max = 16, // maximum length of name |
duke@435 | 98 | arg_length_max = 1024, // maximum length of argument |
duke@435 | 99 | arg_count_max = 3 // maximum number of arguments |
duke@435 | 100 | }; |
duke@435 | 101 | |
duke@435 | 102 | // name of special operation that can be enqueued when all |
duke@435 | 103 | // clients detach |
duke@435 | 104 | static char* detachall_operation_name() { return (char*)"detachall"; } |
duke@435 | 105 | |
duke@435 | 106 | private: |
duke@435 | 107 | char _name[name_length_max+1]; |
duke@435 | 108 | char _arg[arg_count_max][arg_length_max+1]; |
duke@435 | 109 | |
duke@435 | 110 | public: |
duke@435 | 111 | const char* name() const { return _name; } |
duke@435 | 112 | |
duke@435 | 113 | // set the operation name |
duke@435 | 114 | void set_name(char* name) { |
duke@435 | 115 | assert(strlen(name) <= name_length_max, "exceeds maximum name length"); |
duke@435 | 116 | strcpy(_name, name); |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | // get an argument value |
duke@435 | 120 | const char* arg(int i) const { |
duke@435 | 121 | assert(i>=0 && i<arg_count_max, "invalid argument index"); |
duke@435 | 122 | return _arg[i]; |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | // set an argument value |
duke@435 | 126 | void set_arg(int i, char* arg) { |
duke@435 | 127 | assert(i>=0 && i<arg_count_max, "invalid argument index"); |
duke@435 | 128 | if (arg == NULL) { |
duke@435 | 129 | _arg[i][0] = '\0'; |
duke@435 | 130 | } else { |
duke@435 | 131 | assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length"); |
duke@435 | 132 | strcpy(_arg[i], arg); |
duke@435 | 133 | } |
duke@435 | 134 | } |
duke@435 | 135 | |
duke@435 | 136 | // create an operation of a given name |
duke@435 | 137 | AttachOperation(char* name) { |
duke@435 | 138 | set_name(name); |
duke@435 | 139 | for (int i=0; i<arg_count_max; i++) { |
duke@435 | 140 | set_arg(i, NULL); |
duke@435 | 141 | } |
duke@435 | 142 | } |
duke@435 | 143 | |
duke@435 | 144 | // complete operation by sending result code and any result data to the client |
duke@435 | 145 | virtual void complete(jint result, bufferedStream* result_stream) = 0; |
duke@435 | 146 | }; |
duke@435 | 147 | #endif // SERVICES_KERNEL |