Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
Hopi::HopiFileChunks Class Reference
Collaboration diagram for Hopi::HopiFileChunks:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void Add (off_t start, off_t end)
off_t Size (void)
void Size (off_t size)
std::string Path (void)
void Remove (void)
void Release (void)
bool Complete (void)
void Print (void)

Static Public Member Functions

static void Timeout (int t)
static HopiFileChunksGet (std::string path)
static HopiFileChunksGetStuck (void)
static HopiFileChunksGetFirst (void)

Private Types

typedef std::list< std::pair
< off_t, off_t > > 
chunks_t

Private Member Functions

 HopiFileChunks (void)

Private Attributes

chunks_t chunks
off_t size
time_t last_accessed
int refcount
std::map< std::string,
HopiFileChunks >::iterator 
self

Static Private Attributes

static std::map< std::string,
HopiFileChunks
files
static Glib::Mutex lock
static int timeout = 600
static time_t last_timeout = time(NULL)

Detailed Description

Definition at line 36 of file hopi.cpp.


Member Typedef Documentation

typedef std::list<std::pair<off_t,off_t> > Hopi::HopiFileChunks::chunks_t [private]

Definition at line 42 of file hopi.cpp.


Constructor & Destructor Documentation

Definition at line 80 of file hopi.cpp.

                                  :size(0),last_accessed(time(NULL)),refcount(0),self(files.end()) {
}

Here is the caller graph for this function:


Member Function Documentation

void Hopi::HopiFileChunks::Add ( off_t  start,
off_t  end 
)

Definition at line 146 of file hopi.cpp.

                                              {
  lock.lock();
  last_accessed=time(NULL);
  if(end > size) size=end;
  for(chunks_t::iterator chunk = chunks.begin();chunk!=chunks.end();++chunk) {
    if((start >= chunk->first) && (start <= chunk->second)) {
      // New chunk starts within existing chunk
      if(end > chunk->second) {
        // Extend chunk
        chunk->second=end;
        // Merge overlapping chunks
        chunks_t::iterator chunk_ = chunk;
        ++chunk_;
        for(;chunk_!=chunks.end();) {
          if(chunk->second < chunk_->first) break;
          // Merge two chunks
          if(chunk_->second > chunk->second) chunk->second=chunk_->second;
          chunk_=chunks.erase(chunk_);
        };
      };
      lock.unlock();
      return;
    } else if((end >= chunk->first) && (end <= chunk->second)) {
      // New chunk ends within existing chunk
      if(start < chunk->first) {
        // Extend chunk
        chunk->first=start;
      };
      lock.unlock();
      return;
    } else if(end < chunk->first) {
      // New chunk is between existing chunks or first chunk
      chunks.insert(chunk,std::pair<off_t,off_t>(start,end));
      lock.unlock();
      return;
    };
  };
  // New chunk is last chunk or there are no chunks currently
  chunks.insert(chunks.end(),std::pair<off_t,off_t>(start,end));
  lock.unlock();
}

Here is the caller graph for this function:

Definition at line 188 of file hopi.cpp.

                                  {
  lock.lock();
  bool r = ((chunks.size() == 1) &&
            (chunks.begin()->first == 0) &&
            (chunks.begin()->second == size));
  lock.unlock();
  return r;
}

Here is the caller graph for this function:

HopiFileChunks & Hopi::HopiFileChunks::Get ( std::string  path) [static]

Definition at line 123 of file hopi.cpp.

                                                  {
  lock.lock();
  std::map<std::string,HopiFileChunks>::iterator c = files.find(path);
  if(c == files.end()) {
    c=files.insert(std::pair<std::string,HopiFileChunks>(path,HopiFileChunks())).first;
    c->second.self=c;
  }
  ++(c->second.refcount);
  lock.unlock();
  return (c->second);
}

Here is the call graph for this function:

Definition at line 100 of file hopi.cpp.

                                             {
  lock.lock();
  std::map<std::string,HopiFileChunks>::iterator f = files.begin();
  if(f != files.end()) {
    ++(f->second.refcount);
    lock.unlock();
    return &(f->second);
  };
  lock.unlock();
  return NULL;
}

Here is the caller graph for this function:

Definition at line 83 of file hopi.cpp.

                                             {
  if(((int)(time(NULL)-last_timeout)) < timeout) return NULL;
  lock.lock();
  for(std::map<std::string,HopiFileChunks>::iterator f = files.begin();
                    f != files.end();++f) {
    if((f->second.refcount <= 0) && 
       (((int)(time(NULL) - f->second.last_accessed)) >= timeout )) {
      ++(f->second.refcount);
      lock.unlock();
      return &(f->second);
    }
  }
  last_timeout=time(NULL);
  lock.unlock();
  return NULL;
}

Here is the caller graph for this function:

std::string Hopi::HopiFileChunks::Path ( void  ) [inline]

Definition at line 58 of file hopi.cpp.

{ return self->first; };

Here is the caller graph for this function:

void Hopi::HopiFileChunks::Print ( void  )

Definition at line 73 of file hopi.cpp.

                               {
  int n = 0;
  for(chunks_t::iterator c = chunks.begin();c!=chunks.end();++c) {
    Hopi::logger.msg(Arc::DEBUG, "Chunk %u: %u - %u",n,c->first,c->second);
  };
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 135 of file hopi.cpp.

                                 {
  lock.lock();
  if(chunks.empty()) {
    lock.unlock();
    Remove();
  } else {
    --refcount;
    lock.unlock();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 112 of file hopi.cpp.

                                {
  lock.lock();
  --refcount;
  if(refcount <= 0) {
    if(self != files.end()) {
      files.erase(self);
    }
  }
  lock.unlock();
}

Here is the caller graph for this function:

off_t Hopi::HopiFileChunks::Size ( void  ) [inline]

Definition at line 52 of file hopi.cpp.

{ return size; };

Here is the caller graph for this function:

void Hopi::HopiFileChunks::Size ( off_t  size) [inline]

Definition at line 53 of file hopi.cpp.

                        {
    lock.lock();
    if(size > HopiFileChunks::size) HopiFileChunks::size = size;
    lock.unlock();
  };
static void Hopi::HopiFileChunks::Timeout ( int  t) [inline, static]

Definition at line 50 of file hopi.cpp.

{ timeout=t; };

Here is the caller graph for this function:


Member Data Documentation

Definition at line 43 of file hopi.cpp.

std::map< std::string, HopiFileChunks > Hopi::HopiFileChunks::files [static, private]

Definition at line 38 of file hopi.cpp.

Definition at line 45 of file hopi.cpp.

time_t Hopi::HopiFileChunks::last_timeout = time(NULL) [static, private]

Definition at line 41 of file hopi.cpp.

Glib::Mutex Hopi::HopiFileChunks::lock [static, private]

Definition at line 39 of file hopi.cpp.

Definition at line 46 of file hopi.cpp.

std::map<std::string,HopiFileChunks>::iterator Hopi::HopiFileChunks::self [private]

Definition at line 47 of file hopi.cpp.

off_t Hopi::HopiFileChunks::size [private]

Definition at line 44 of file hopi.cpp.

int Hopi::HopiFileChunks::timeout = 600 [static, private]

Definition at line 40 of file hopi.cpp.


The documentation for this class was generated from the following file: