• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Machine.h

Go to the documentation of this file.
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 
00032 //
00033 //  The Machine is the set of processes which share part of an
00034 //  address space.
00035 //
00036 
00037 #ifndef _Machine_h
00038 #define _Machine_h
00039 
00040 //
00041 // Timeout the Machine * this amount of time after they
00042 // fall out of the current configuration that are deleted.
00043 //
00044 #define MACHINE_TIMEOUT            (HRTIME_DAY*2)
00045 
00046 
00047 //
00048 //  This is the time processors should delay before freeing up resouces
00049 //  which are shared with other threads in non-long running operations.
00050 //  For example, a Machine * is returned by the hash and used to do
00051 //  a remote invoke.  For the pointer to remain valid (or be recognized as
00052 //  invalid) he resource should not be raclaimed for NO_RACE_DELAY.
00053 //
00054 //  Long running operations should use more sophisticated synchronization.
00055 //
00056 #define NO_RACE_DELAY                  HRTIME_HOUR      // a long long time
00057 
00058 //#include "Connection.h"
00059 
00060 class ClusterHandler;           // Leave this a class - VC++ gets very anal  ~SR
00061 
00062 struct Machine: Server
00063 {
00064   bool dead;
00065   char *hostname;
00066   int hostname_len;
00067   //
00068   // The network address of the current machine,
00069   // stored in network byte order
00070   //
00071   unsigned int ip;
00072   int cluster_port;
00073 
00074     Link<Machine> link;
00075 
00076   // default for localhost
00077     Machine(char *hostname = NULL, unsigned int ip = 0, int acluster_port = 0);
00078    ~Machine();
00079 
00080   // Cluster message protocol version
00081   uint16_t msg_proto_major;
00082   uint16_t msg_proto_minor;
00083 
00084   // Private data for ClusterProcessor
00085   //
00086   ClusterHandler *clusterHandler;
00087 };
00088 
00089 struct MachineListElement
00090 {
00091   unsigned int ip;
00092   int port;
00093 };
00094 
00095 struct MachineList
00096 {
00097   int n;
00098   MachineListElement machine[1];
00099   MachineListElement *find(unsigned int ip, int port = 0) {
00100     for (int i = 0; i < n; i++)
00101       if (machine[i].ip == ip && (!port || machine[i].port == port))
00102         return &machine[i];
00103     return NULL;
00104   }
00105 };
00106 
00107 MachineList *read_MachineList(char *filename, int test_fd = -1);
00108 void free_MachineList(MachineList * l);
00109 
00110 #ifdef FIXME_CONFIG
00111 struct clusterConfigFile: configFile
00112 {
00113   char *parseFile(int fd)
00114   {
00115     return (char *) read_MachineList(NULL, fd);
00116   }
00117 };
00118 #endif
00119 
00120 inkcoreapi Machine *this_machine();
00121 void create_this_machine();
00122 
00123 void free_Machine(Machine * m);
00124 
00125 MachineList *the_machines_config();
00126 MachineList *the_cluster_config();
00127 extern ProxyMutex *the_cluster_config_mutex;
00128 
00129 #define INK_GETHOSTBYNAME_R_DATA_SIZE 10000
00130 struct ink_gethostbyname_r_data
00131 {
00132   int herrno;
00133   struct hostent ent;
00134   char buf[INK_GETHOSTBYNAME_R_DATA_SIZE];
00135 };
00136 
00137 struct hostent *ink_gethostbyname_r(char *hostname, ink_gethostbyname_r_data * data);
00138 //
00139 // Private
00140 //
00141 extern MachineList *machines_config;
00142 extern MachineList *cluster_config;
00143 
00144 
00145 #endif /* _Machine_h */

Generated by  doxygen 1.7.1