00001 /** @file 00002 00003 A brief file description 00004 00005 @section license License 00006 00007 Licensed to the Apache Software Foundation (ASF) under one 00008 or more contributor license agreements. See the NOTICE file 00009 distributed with this work for additional information 00010 regarding copyright ownership. The ASF licenses this file 00011 to you under the Apache License, Version 2.0 (the 00012 "License"); you may not use this file except in compliance 00013 with the License. You may obtain a copy of the License at 00014 00015 http://www.apache.org/licenses/LICENSE-2.0 00016 00017 Unless required by applicable law or agreed to in writing, software 00018 distributed under the License is distributed on an "AS IS" BASIS, 00019 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 See the License for the specific language governing permissions and 00021 limitations under the License. 00022 */ 00023 00024 /**************************************************************************** 00025 00026 Machine.h 00027 ****************************************************************************/ 00028 00029 00030 // 00031 // The Machine is the set of processes which share part of an 00032 // address space. 00033 // 00034 00035 #ifndef _P_ClusterMachine_h 00036 #define _P_ClusterMachine_h 00037 00038 // 00039 // Timeout the Machine * this amount of time after they 00040 // fall out of the current configuration that are deleted. 00041 // 00042 #define MACHINE_TIMEOUT (HRTIME_DAY*2) 00043 00044 00045 // 00046 // This is the time processors should delay before freeing up resouces 00047 // which are shared with other threads in non-long running operations. 00048 // For example, a Machine * is returned by the hash and used to do 00049 // a remote invoke. For the pointer to remain valid (or be recognized as 00050 // invalid) he resource should not be raclaimed for NO_RACE_DELAY. 00051 // 00052 // Long running operations should use more sophisticated synchronization. 00053 // 00054 #define NO_RACE_DELAY HRTIME_HOUR // a long long time 00055 00056 struct ClusterHandler; // Leave this a class - VC++ gets very anal ~SR -- which version of VC++? ~igalic 00057 00058 struct ClusterMachine: public Server 00059 { 00060 bool dead; 00061 char *hostname; 00062 int hostname_len; 00063 // 00064 // The network address of the current machine, 00065 // stored in network byte order 00066 // 00067 unsigned int ip; 00068 int cluster_port; 00069 int num_connections; 00070 int now_connections; 00071 int free_connections; 00072 int64_t rr_count; 00073 00074 Link<ClusterMachine> link; 00075 00076 // default for localhost 00077 ClusterMachine(char *hostname = NULL, unsigned int ip = 0, int acluster_port = 0); 00078 ~ClusterMachine(); 00079 ClusterHandler *pop_ClusterHandler(int no_rr = 0); 00080 00081 // Cluster message protocol version 00082 uint16_t msg_proto_major; 00083 uint16_t msg_proto_minor; 00084 00085 // Private data for ClusterProcessor 00086 // 00087 ClusterHandler **clusterHandlers; 00088 }; 00089 00090 struct MachineListElement 00091 { 00092 unsigned int ip; 00093 int port; 00094 }; 00095 00096 struct MachineList 00097 { 00098 int n; 00099 MachineListElement machine[1]; 00100 MachineListElement *find(unsigned int ip, int port = 0) { 00101 for (int i = 0; i < n; i++) 00102 if (machine[i].ip == ip && (!port || machine[i].port == port)) 00103 return &machine[i]; 00104 return NULL; 00105 } 00106 }; 00107 00108 MachineList *read_MachineList(char *filename, int test_fd = -1); 00109 void free_MachineList(MachineList * l); 00110 00111 struct clusterConfigFile 00112 { 00113 char *parseFile(int fd) 00114 { 00115 return (char *) read_MachineList(NULL, fd); 00116 } 00117 }; 00118 00119 inkcoreapi ClusterMachine *this_cluster_machine(); 00120 void create_this_cluster_machine(); 00121 00122 void free_ClusterMachine(ClusterMachine * m); 00123 00124 MachineList *the_cluster_machines_config(); 00125 MachineList *the_cluster_config(); 00126 extern ProxyMutex *the_cluster_config_mutex; 00127 00128 // 00129 // Private 00130 // 00131 extern MachineList *machines_config; 00132 extern MachineList *cluster_config; 00133 00134 00135 #endif /* _Machine_h */