Ignore:
Timestamp:
Jun 11, 2015, 3:07:11 PM (9 years ago)
Author:
djay
Message:

Better concurrency gesture for asynchronous requests, add db backend support for status informations.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/zoo_service_loader.c

    r640 r652  
    16691669  }
    16701670
     1671
     1672  // Define each env variable in runing environment
    16711673  maps *curs = getMaps (m, "env");
    16721674  if (curs != NULL)
     
    17281730#endif
    17291731
    1730   /**
    1731    * Need to check if we need to fork to load a status enabled
    1732    */
     1732  // Need to check if we need to fork to load a status enabled
    17331733  r_inputs = NULL;
    17341734  map *store = getMap (request_inputs, "storeExecuteResponse");
     
    17871787  _tmpMaps->name = zStrdup ("lenv");
    17881788  char tmpBuff[100];
    1789   semid lid = getShmLockId (NULL, 1);
    1790   lockShm (lid);
    17911789  struct ztimeval tp;
    17921790  if (zGettimeofday (&tp, NULL) == 0)
     
    17941792  else
    17951793    sprintf (tmpBuff, "%i", (cpid + (int) time (NULL)));
    1796   unlockShm (lid);
    1797   removeShmLock (NULL, 1);
    1798   _tmpMaps->content = createMap ("usid", tmpBuff);
     1794  _tmpMaps->content = createMap ("osid", tmpBuff);
    17991795  _tmpMaps->next = NULL;
    18001796  sprintf (tmpBuff, "%i", cpid);
     
    18021798  char* tmpUuid=get_uuid();
    18031799  addToMap (_tmpMaps->content, "uusid", tmpUuid);
     1800  addToMap (_tmpMaps->content, "usid", tmpUuid);
    18041801  free(tmpUuid);
    18051802  addToMap (_tmpMaps->content, "status", "0");
     
    19101907    }
    19111908#endif
    1912   char *fbkp, *fbkp1;
     1909  char *fbkp, *fbkpid, *fbkp1, *flog;
    19131910  FILE *f0, *f1;
    19141911  if (status != NULL)
     
    19771974           * process answer to http client.
    19781975           */
    1979 #ifndef WIN32
    1980           zSleep (1);
    1981 #endif
    1982           r_inputs = getMapFromMaps (m, "lenv", "usid");
     1976          map* usid = getMapFromMaps (m, "lenv", "uusid");
     1977          r_inputs = getMapFromMaps (m, "lenv", "osid");
    19831978          int cpid = atoi (r_inputs->value);
    19841979          r_inputs = getMapFromMaps (m, "main", "tmpPath");
    1985           //map *r_inputs1 = getMap (s1->content, "ServiceProvider");
    1986                   map* r_inputs1 = createMap("ServiceName", s1->name);
    1987 
     1980          map* r_inputs1 = createMap("ServiceName", s1->name);
     1981
     1982          // Create PID file referencing the OS process identifier
     1983          fbkpid =
     1984            (char *)
     1985            malloc ((strlen (r_inputs->value) +
     1986                     strlen (usid->value) + 7) * sizeof (char));
     1987          sprintf (fbkpid, "%s/%s.pid", r_inputs->value, usid->value);
     1988
     1989          f0 = freopen (fbkpid, "w+", stdout);
     1990          fprintf(stdout,"%d",getpid());
     1991          fflush(stdout);
     1992
     1993          // Create SID file referencing the semaphore name
    19881994          fbkp =
    19891995            (char *)
    19901996            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    1991                      1024) * sizeof (char));
    1992           sprintf (fbkp, "%s/%s_%d.xml", r_inputs->value, r_inputs1->value,
    1993                    cpid);
    1994           char *flog =
     1997                     strlen (usid->value) + 7) * sizeof (char));
     1998          sprintf (fbkp, "%s/%s.sid", r_inputs->value, usid->value);
     1999
     2000          FILE* f2 = fopen (fbkp, "w+");
     2001          map* tmpm=getMapFromMaps (m, "lenv", "osid");
     2002          fprintf(f2,"%s",tmpm->value);
     2003          fflush(f2);
     2004          fclose(f2);
     2005          free(fbkp);
     2006
     2007          fbkp =
    19952008            (char *)
    19962009            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    1997                      1024) * sizeof (char));
    1998           sprintf (flog, "%s/%s_%d_error.log", r_inputs->value,
    1999                    r_inputs1->value, cpid);
     2010                     strlen (usid->value) + 7) * sizeof (char));
     2011          sprintf (fbkp, "%s/%s_%s.xml", r_inputs->value, r_inputs1->value,
     2012                   usid->value);
     2013          flog =
     2014            (char *)
     2015            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
     2016                     strlen (usid->value) + 13) * sizeof (char));
     2017          sprintf (flog, "%s/%s_%s_error.log", r_inputs->value,
     2018                   r_inputs1->value, usid->value);
    20002019#ifdef DEBUG
    20012020          fprintf (stderr, "RUN IN BACKGROUND MODE \n");
     
    20052024#endif
    20062025          freopen (flog, "w+", stderr);
    2007           semid lid = getShmLockId (m, 1);
    20082026          fflush (stderr);
    2009           if (lid < 0)
    2010             {
    2011               return errorException (m, _("Lock failed"),
    2012                               "InternalError", NULL);
    2013             }
    2014           else
    2015             {
    2016               if (lockShm (lid) < 0)
    2017                 {
    2018                   return errorException (m, _("Lock failed"),
    2019                                          "InternalError", NULL);
    2020                 }
    2021             }
    20222027          f0 = freopen (fbkp, "w+", stdout);
    20232028          rewind (stdout);
     
    20362041                                request_output_real_format);
    20372042          fflush (stdout);
    2038           unlockShm (lid);
     2043#ifdef RELY_ON_DB
     2044          init_sql(m);
     2045          recordServiceStatus(m);
     2046          recordResponse(m,fbkp);
     2047#endif
    20392048          fflush (stderr);
    20402049          fbkp1 =
    20412050            (char *)
    20422051            malloc ((strlen (r_inputs->value) + strlen (r_inputs1->value) +
    2043                      1024) * sizeof (char));
    2044           sprintf (fbkp1, "%s/%s_final_%d.xml", r_inputs->value,
    2045                    r_inputs1->value, cpid);
     2052                     strlen (usid->value) + 13) * sizeof (char));
     2053          sprintf (fbkp1, "%s/%s_final_%s.xml", r_inputs->value,
     2054                   r_inputs1->value, usid->value);
    20462055
    20472056          f1 = freopen (fbkp1, "w+", stdout);
    2048           free (flog);
    20492057
    20502058          if(validateRequest(&m,s1,request_inputs, &request_input_real_format,&request_output_real_format,&hInternet)<0){
     
    20622070            free (tmpmaps);
    20632071            fflush (stdout);
    2064             unlockShm (lid);
    20652072            fflush (stderr);
     2073            unhandleStatus (m);
    20662074            return -1;
    20672075          }
     
    20732081      else
    20742082        {
    2075       /**
    2076        * error server don't accept the process need to output a valid
    2077        * error response here !!!
    2078        */
     2083          /**
     2084           * error server don't accept the process need to output a valid
     2085           * error response here !!!
     2086           */
    20792087          eres = -1;
    20802088          errorException (m, _("Unable to run the child process properly"),
     
    21092117      fclose (stdout);
    21102118      fclose (stderr);
    2111     /**
    2112      * Dump back the final file fbkp1 to fbkp
    2113      */
     2119      /**
     2120       * Dump back the final file fbkp1 to fbkp
     2121       */
    21142122      fclose (f0);
    21152123      fclose (f1);
    21162124      FILE *f2 = fopen (fbkp1, "rb");
     2125#ifndef RELY_ON_DB
    21172126      semid lid = getShmLockId (m, 1);
    21182127      if (lid < 0)
    21192128        return -1;
    21202129      lockShm (lid);
     2130#endif
    21212131      FILE *f3 = fopen (fbkp, "wb+");
    21222132      free (fbkp);
     
    21292139      fclose (f2);
    21302140      fclose (f3);
    2131       unlockShm (lid);
     2141      unlink (fbkpid);
     2142#ifndef RELY_ON_DB
     2143      removeShmLock (m, 1);
     2144#else
     2145      recordResponse(m,fbkp1);
     2146#endif
    21322147      unlink (fbkp1);
     2148      unlink (flog);
     2149      unhandleStatus (m);
     2150      free(fbkpid);
     2151      free (flog);
    21332152      free (fbkp1);
    21342153      free (tmps1);
    2135       unhandleStatus (m);
    21362154    }
    21372155
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png