Remote file access system Cage


5. Using the Cage class

class cage. Cage ( cage_name = "", pagesize = 0, numpages = 0, maxstrlen = 0, server_ip = {}, wait = 0 , awake = False, cache_file = "" )

From this class, objects are created that interact with file servers and contain buffer memory.

Parameters

  • cage_name ( str ) - the conditional name of the object that is used to identify clients on the server side
  • pagesize ( int ) - the size of one page of buffer memory (in bytes)
  • numpages ( int ) - the number of pages of buffer memory
  • maxstrlen ( int ) - the maximum length of the byte string in write and read operations
  • server_ip ( dict ) - a dictionary with the addresses of the servers used, where the key is the conditional name of the server (server id inside the application), and the value is a string with the address: “ip address : port ”or“ DNS: port ”(matching names and real addresses is temporary, it can be changed)
  • wait ( int ) - time to wait for a response from the server when receiving ports (in seconds)
  • awake ( boolean ) - the flag of the method of creating the object ( False - if a new object is created, True - if the object is created from previously “minimized” - using the “hibernation” operation, by default False)
  • cache_file ( str ) - file name for hibernation

Methods

Cage. file_create ( server, path ) - create a new file

Arguments

  • server is the server id (link to the server’s network address and port)
  • path - the full path to the file on the server

Returns

  • True on success
  • False for a system error (I / O, communication, etc.)
  • ReturnCode - if the file was not created, but this is not an error: -1 - if a file with the same name already exists and is closed, -2 - if a file with the same name already exists and is opened by this client, “Wm”, “rs” or “ws” - if a file with the same name already exists and is opened by another client in the corresponding mode (see the Cage.open method below)

Cage. file_rename ( server, path, new_name ) - rename the file

Arguments

  • new_name - new file name

Returns

  • True the file was successfully renamed
  • False the file does not exist, or there is already a file with a new name, or cannot be renamed due to blocking by another client, or due to a system error

Cage. file_remove ( server, path ) - delete file

Returns

  • True file deleted successfully
  • False the file does not exist, or cannot be deleted due to blocking by another client, or due to a system error

Cage. open ( server, path, mod ) - open file

Arguments

  • mod - file open mode: "wm" - exclusive (read / write), "rs" - read only, and shared only for reading by other clients, "ws" - read / write, and shared read-only by other clients. Files in rs and ws modes are “physically” opened on the server only by the first client (let's call it “owner”), for the second and subsequent servers the server no longer opens the file, but uses it in the resource sharing mode (that is, it opens “virtually”)

Returns

  • ReturnCode = fchannel - if the file is open, fchannel - assigned or already existing (that is, the file was previously opened by this client) channel number is a positive integer
  • False the file does not exist, or the file is already opened by this client in another mode, or it cannot be opened in the desired mode due to blocking by another client, or when the limit on the number of open files is exceeded, or when the system error

Cage. close ( fchannel ) - close the file

Arguments

  • fchannel - channel number

Returns

  • True for the client, the file was successfully closed (physically or “virtually”)
  • False the file is not closed due to an error in the channel number or due to a system error. If the first client closes the file that other clients use in addition to it, the server does not physically close the file, and the first in order, the remaining client becomes the "owner"

Cage. write ( fchannel, begin, data ) - write the byte string to the file

Arguments

  • begin - the first position in the file (from zero or more)
  • data - string of bytes

Returns

  • True the recording was successful
  • False in case of an error in the parameter values, or inability to record due to the file channel mode, or in case of a system error

Cage. read ( fchannel, begin, len_data ) - read the byte string from the file

Arguments

  • len_data - string length (bytes)

Returns

  • byte string if reading was successful
  • False if there is an error in the parameter values, or with a system error

Cage. remote ( server ) - get general information about all channels open on the server

Returns

  • dictionary with information - if successful
  • False in case of an error in the parameter value, or in case of a system error

Cage. put_pages ( fchannel ) - “pushes” from the buffer to the server all pages of the specified channel that have been modified

It is used at those points in the algorithm when you need to be sure that all operations on the channel are physically stored in a file on the server.

Returns

  • True the recording was successful
  • False if there is an error in the parameter value, or an inability to write due to the channel mode of the file, or with a system error

Cage. push_all () - “pushes” from the buffer to the server all pages of all channels for the Cage class instance that have been modified.

Used at those points in the algorithm when you need to be sure that all operations on all channels are stored on the server.

The method returns:

Returns

  • True the recording was successful
  • False if there is an error in the parameter value, or an inability to write due to the channel mode of the file, or with a system error